【问题标题】:Add "Tags" to wp.newPost Wordpress将“标签”添加到 wp.newPost Wordpress
【发布时间】:2014-03-19 20:47:46
【问题描述】:

我制作了一个 php 脚本,可以在 wordpress 网站上发布一篇新文章。

这是我的代码的一部分:

$terms_names = array('post_tag' => $tags);

$content = array(
'post_type' => 'post',
'post_status'=>'pending',
'post_title'=> 'TEST',
'post_author'=> 1,
'post_excerpt' => 'SOMETEXT',
'post_content'=> 'POSTBODY',
'post_date_gmt' => '',
'comment_status'=>1
'ping_status'=>0,
'post_thumbnail' => $results,
'terms_names' => $terms_names

);
$params = array(0,$username,$password,$content,false);
$request = xmlrpc_encode_request('wp.newPost',$params);

有可能添加帖子标签吗? 谢谢大家

问候

编辑:

问题已解决:) 我添加了$terms_name 数组, 我刚刚编辑了我的代码:)

问候

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    只需将标签添加到您的数组(编辑:作为数组或不带)

    $tags = array('tag1', 'tag2');
    $content = array(
    'post_type'     => 'post',
    'post_status'   =>'pending',
    'post_title'    => 'TEST',
    'post_author'   => 1,
    'post_excerpt'  => 'SOMETEXT',
    'post_content'  => 'POSTBODY',
    'post_date_gmt' => '',
    'comment_status'=> 1
    'ping_status'   => 0,
    'post_thumbnail'=> $results,
    'tags_input'    => $tags
    );
    

    wp.newPost 接受 wp_insert_post 支持的所有文件

    【讨论】:

    • 如何在 curl 中使用它?因为我把 $request 放在 Curl curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    • 是的,所有其他信息都正常,帖子创建成功,但标签没有出现
    • 确保它适用于来自 dbase 的标签,我将进行测试并更新我的答案
    • 终于找到了解决方案:D 我用我的解决方案编辑了我的第一篇文章
    • 谢谢 Michal,非常感谢您的帮助 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多