投稿がまだ適切な広告主名で終了していない場合に CJ Web API から新しい投稿を作成する次のスクリプトを作成しましたが、スクリプトは投稿の終了をチェックせずにそれを行います。すなわち。if...else 効果がないので、どうすれば修正できますか? 私はPHPが初めてなので、私のnoobsenseを無視してください、ありがとう。
foreach ($data->products[0] as $product)
{
// Sanitize data.
$price = number_format((float)$product->price, 2, '.', ' ');
$image = '<a href="'.$product->{'buy-url'}.'"><img src="'.$product->{'image-url'}.
'" style="float: right"/></a>';
$pd = $image.$product->description .'<a href="'.$product->{'buy-url'}.
'">...For more details and to buy it click here</a>';
$post_slug = $product->{'advertiser-name'};
$args=array(
'cat' => $_GET['cat'],
'name' => $post_slug,
'post_type' => 'post',
'post_status' => 'publish'
);
$my_query = new WP_Query($args);
if($my_query->have_posts()) {
echo 'post already exits';
wp_reset_query(); // Restore global post data stomped by the_post().
}
else{
$p = array('post_title' => $product->{'advertiser-name'},
'post_content' => $pd,
'post_status' => 'publish',
'post_author' => 1,
'post_category' =>array($_GET['cat']));
$pr = wp_insert_post( $p, $wp_error );
echo $pr;
wp_reset_query(); // Restore global post data stomped by the_post().
}