0
게시물이 이미 정상적인 광고주 이름으로 종료되지 않지만 스크립트가없는 경우 CJ web api에서 새 게시물을 작성하기 위해 다음 스크립트를 작성했습니다. 게시물 출구를 점검하는지 여부. 예. 그들의 효과는 다른 것인데, 어떻게 해결할 수 있습니까? 나는 PHP에 익숙하지 않으므로 제 noobsense를 무시하십시오. 고마워요.게시물 제목을 비교하고 일치하는 항목이없는 경우 WordPress에 PHP가 포함 된 새 게시물을 작성하십시오.
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().
}
덕분에 수행하려고 다음
print_r($my_query->have_posts());
을 시도, 나는 wpdb 클래스를 통해 그것을 해결 –