我正在尝试使用 PHRETS 从 rets 服务器在 wordpress 中添加帖子。不幸的是,正在添加重复的帖子。我已经使用 WP Query 使用元键和值检查现有帖子。当我尝试添加 10 或 50 个帖子时,此代码运行良好,但是当我将限制设置为 4000 时,它开始添加重复的帖子。我已经多次运行此代码并多次刷新数据库。这是一个代码示例:
$query = "(922=MIAMI), (246=A)";
$search = $rets->SearchQuery("Property", $class, $query, array("SystemName" => 1, 'Limit' =>4550));
if ($rets->NumRows($search) > 0) {
$fields_order = $rets->SearchGetFields($search);
while ($record = $rets->FetchRow($search)) {
foreach ($fields_order as $fo) {
if ($fo == 'sysid') { $systemid = $record[$fo] ; }
if ($fo == '881') { $saddress = isset($record[$fo]) ? $record[$fo] : ""; }
if ($fo == '214') { $sremarks = isset($record[$fo]) ? $record[$fo] : ""; }
}
$porpertytitle = $saddress;
$args = array(
'numberposts' => -1,
'post_type' => 'property',
'post_status' => 'publish',
'meta_key' =>'sysid',
'meta_value' => $systemid
);
$the_query = new WP_Query($args);
if($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
unset($systemid);
unset($args);
}
} else {
$my_listing = array(
'post_title' => $porpertytitle,
'post_type' => 'property',
'post_content' => $sremarks,
'post_status' => 'publish',
);
$listing_post_id = wp_insert_post($my_listing);
if($listing_post_id > 0) {
update_post_meta($listing_post_id, 'sysid', $systemid);
}
unset($systemid);
unset($args);
unset($listing_post_id);
}
wp_reset_postdata();
}
}
对不起这个长代码。但我也尝试在每个循环后取消设置变量但不工作。