要在post meta中保存链接,可以使用update_post_meta
例如:
$url = "http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950"
$my_post = array(
\'post_title\' => "$title",
\'post_content\' => "$content",
\'post_status\' => \'draft\',
\'post_author\' => 1,
\'post_category\' => array(1),
);
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id,\'source_link\',$url);
为了防止插入,请添加一个简单的条件检查:
$args = array("meta_key" => "source_link", "meta_value" =>$url);
$posts = get_posts($args);
if (count($posts) < 0){
//add new post
}
<小时>
if (count($posts) < 0){
//add new post
}
不工作,请将其更改为
if (empty($posts)){
//add new post
}