XML フィードからデータを抽出し、そのすべてのデータを wp_insert_post() 関数で投稿する Wordpress 用のプラグインを構築しています。プラグインは 1 時間ごとに実行されるため、二重投稿を防止する必要があります。
フィルターを追加して、XML フィードの post_date と Wordpress の post_date を比較しようとしました (投稿に XML と同じ post_date を指定したため) が、うまくいかず、理由がわかりません..
これが私のコードです:
add_filter('posts_where', 'checkPosts'); //I add a filter
$query = new WP_Query('post_type=event'); // Make a query for the custom post_type 'event'
if(!$query->have_posts()) { //If it doesn't have any posts with the same post_date post it
$post_id = wp_insert_post($post);
wp_set_object_terms($post_id, $genres, 'genre');
}
remove_filter('posts_where', 'checkPosts');
function checkPosts($where = '') {
$where .= " AND post_date = ".$post_date;
return $where;
}
誰かが私の間違いを教えてくれますか、または Wordpress で同一の投稿を防ぐための別のテクニックを教えてくれませんか?