Function Reference: geodir_temp_set_post_attachment
Summary
temp function to set post attachment.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory
Change Log
Since: 1.0.0
Source File
geodir_temp_set_post_attachment() is located in geodirectory_hooks_actions.php [Line: 2253]
Source Code
function geodir_temp_set_post_attachment() { global $wpdb, $plugin_prefix; $all_postypes = geodir_get_posttypes(); foreach ($all_postypes as $posttype) { $tablename = $plugin_prefix . $posttype . '_detail'; $get_post_data = $wpdb->get_results("SELECT post_id FROM " . $tablename); if (!empty($get_post_data)) { foreach ($get_post_data as $data) { $post_id = $data->post_id; $attachment_data = $wpdb->get_results("SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id =" . $post_id . " AND file!=''"); if (!empty($attachment_data)) { foreach ($attachment_data as $attach) { $file_info = pathinfo($attach->file); $sub_dir = ''; if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') $sub_dir = stripslashes_deep($file_info['dirname']); $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs $uploads_path = $uploads['basedir']; $file_name = $file_info['basename']; $img_arr['path'] = $uploads_path . $sub_dir . '/' . $file_name; if (!file_exists($img_arr['path'])) { $wpdb->query("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE ID=" . $attach->ID); } } $attachment_data = $wpdb->get_row("SELECT ID, MIN(`menu_order`) FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id=" . $post_id . " GROUP BY post_id"); if (!empty($attachment_data)) { if ($attachment_data->ID) $wpdb->query("UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order=1 WHERE ID=" . $attachment_data->ID); } else { if (has_post_thumbnail($post_id)) { $post_thumbnail_id = get_post_thumbnail_id($post_id); wp_delete_attachment($post_thumbnail_id); } } $wpdb->query("UPDATE " . $tablename . " SET featured_image='' WHERE post_id =" . $post_id); geodir_set_wp_featured_image($post_id); } } } } }