Php Wordpress:如何通过编程创建帖子并在发布前检查重复
我有一个脚本,可以从API获取一些数据,我需要将这些数据(帖子数组)作为帖子插入WordPress 因此,我需要做的是:Php Wordpress:如何通过编程创建帖子并在发布前检查重复,php,mysql,wordpress,wordpress-theming,Php,Mysql,Wordpress,Wordpress Theming,我有一个脚本,可以从API获取一些数据,我需要将这些数据(帖子数组)作为帖子插入WordPress 因此,我需要做的是: 检查每个帖子是否存在,以通过post\u name 或slug或title如果可能 我在名为paper 我需要插入报纸的标题 我也注册了自定义字段的职位和关键是 fifu\u img\u url、fifu\u img\u alt和\u cmb\u link所以我需要一种方法为每个帖子向这些键插入数据 这将是一个rest API post请求,我已经完成了API部分并通过pos
post\u name
或slug
或title
如果可能paper
我需要插入报纸的标题fifu\u img\u url
、fifu\u img\u alt
和\u cmb\u link
所以我需要一种方法为每个帖子向这些键插入数据这将是一个rest API post请求,我已经完成了API部分并通过post请求接收数据,剩下的是按照上面所述处理数据。我已经通过以下步骤完成了这项工作
$is\u post\u exists=post\u exists($post->title);
如果($is\u post\u exists==0){
$post\u id=wp\u insert\u post(数组(
'post_title'=>$post->title,
“发布日期”=>$post->date,
“post_内容”=>$post->摘录,
“后作者”=>1,
“发布状态”=>“发布”,
“元输入”=>数组(
“fifu\u图像\u url”=>$post->图像,
“fifu_image_alt”=>$post->title,
“\u cmb\u link”=>$post->link,
)
));
$termObj=get_term_by('name',$post->paper->title,'paper');
设置发布格式($post\u id,$post->type);
如果($termObj){
wp_set_object_terms($post_id,array($termObj->term_id),'paper');
}否则{
$new_paper=wp_insert_term($post->paper->title,'paper');
wp_set_object_terms($post_id,array($new_paper['term_id']),'paper');
}
如果($post_id){
$added_posts[]=$post_id;
}
}否则{
$not_added_posts[]=$post->id;
}
我无法使用fifu\u image\u url获取特色图像。你能帮忙吗?fifu\u image\u url是一个自定义字段,我没有注册特色图片,要以任何方式获取特色图片,你必须使用获取文章缩略图()
我需要在每篇文章的参数中设置一个fifu_image_url。我正在使用PHP的XMLRPC发布文章,但是文章没有附带特色图片。我已经在自定义字段中定义了fifu_image_url以及他们定义的文档,但是特色图片没有出现。检查代码:$content=array('terms'=>array('category'=>array($YourCategoryID)),'post\u type'=>'post','post\u name'=>$slug,//对于slug'post\u status'=>'draft','post\u title'=>$title',post\u content'=>$body,'ping\u status'=>'closed comment','post\u status'=>'closed','meta\u input'=>数组('fifu_image_url'=>$img_url,'fifu_image_alt'=>$title,)