我需要更新它但是在一个条件下如果post已经存在则更新它,如果没有则插入它。
$values = "SELECT post_id FROM `wp_postmeta` where `meta_key` = 'embed_code' AND `meta_value` ='$vid->embed_code' ";
$metavalues = $wpdb->get_var($values);
echo '<pre>';
print_r($metavalues);
if ($metavalues !=='')
{
$postID = wp_insert_post(array(
'ID' => 'post_id',
'post_content' => $vid->description,
'post_title' => $vid->name,
'post_status' => 'publish',
'post_type' => 'labelv',
'post_category' => array($label->name),
));
add_post_meta($postID, 'original_file_name', $vid->original_file_name);
add_post_meta($postID, 'publishing_rule_id', $vid->publishing_rule_id);
add_post_meta($postID, 'player_id', $vid->player_id);
add_post_meta($postID, 'embed_code', $vid->embed_code);
add_post_meta($postID, 'duration', $vid->duration);
add_post_meta($postID, 'external_id', $vid->external_id);
add_post_meta($postID, 'preview_image_url', $vid->preview_image_url);
add_post_meta($postID, 'time_restrictions', $vid->time_restrictions);
add_post_meta($postID, 'updated_at', $vid->updated_at);
add_post_meta($postID, 'hosted_at', $vid->hosted_at);
add_post_meta($postID, 'ad_set_id', $vid->ad_set_id);
add_post_meta($postID, 'status', $vid->status);
}
else
{
wp_update_post(array(
'post_content' => $vid->description,
'post_title' => $vid->name,
'post_status' => 'publish',
'post_type' => 'labelv',
'post_category' => array($label->name),
));
update_post_meta($postID, 'original_file_name', $vid->original_file_name);
update_post_meta($postID, 'publishing_rule_id', $vid->publishing_rule_id);
update_post_meta($postID, 'player_id', $vid->player_id);
update_post_meta($postID, 'embed_code', $vid->embed_code);
update_post_meta($postID, 'duration', $vid->duration);
update_post_meta($postID, 'external_id', $vid->external_id);
update_post_meta($postID, 'preview_image_url', $vid->preview_image_url);
update_post_meta($postID, 'time_restrictions', $vid->time_restrictions);
update_post_meta($postID, 'updated_at', $vid->updated_at);
update_post_meta($postID, 'hosted_at', $vid->hosted_at);
update_post_meta($postID, 'ad_set_id', $vid->ad_set_id);
update_post_meta($postID, 'status', $vid->status);
}