找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 23|回复: 2

Wordpress 大佬请进。

[复制链接]

253

主题

426

回帖

1635

积分

金牌会员

积分
1635
发表于 2019-1-15 13:06:42 | 显示全部楼层 |阅读模式
本帖最后由 yaoruisheng 于 2019-1-15 16:16 编辑

开门见山,我首先引用wp-load.php

[ol]
  • include_once("../wp-load.php");[/ol]复制代码

    然后用wp_insert_post 这个函数直接发表一篇文章
    [ol]
  • $post_id = wp_insert_post( $post , $error);[/ol]复制代码

    其中$post这个变量,我打印出来的结果是
    [ol]
  • array(8) {
  •   ["post_author"]=>
  •   int(1)
  •   ["post_content"]=>
  •   string(115) ""
  •   ["post_title"]=>
  •   string(93) "谷歌,搜你所搜!"
  •   ["post_status"]=>
  •   string(7) "publish"
  •   ["post_type"]=>
  •   string(4) "post"
  •   ["post_category"]=>
  •   array(1) {
  •     [0]=>
  •     int(3)
  •   }
  •   ["tax_input"]=>
  •   array(1) {
  •     ["post_format"]=>
  •     string(5) "video"
  •   }
  •   ["meta_input"]=>
  •   array(1) {
  •     ["gg_auto_id"]=>
  •     string(11) "1VQbu3FcNHU"
  •   }
  • }
  • [/ol]复制代码

    问:为什么最终结果是文章发布了,但是只有标题,没有内容,并且文章分类也不对?



    经过折腾,发现是权限问题,内容为空是wordpress过滤掉内容里的iframe标签,需要用kses_remove_filters()函数关闭过滤器。

    文章的类别无法通过tax_input进行设置,由函数wp_insert_post源码https://developer.wordpress.org/reference/functions/wp_insert_post/  可见:

    [ol]
  •             if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
  •                 wp_set_post_terms( $post_ID, $tags, $taxonomy );
  •             }
  • [/ol]复制代码

    只有登陆用户才可以wp_set_post_terms。
  • 回复

    使用道具 举报

    92

    主题

    1199

    回帖

    2720

    积分

    金牌会员

    积分
    2720
    发表于 2019-1-15 13:42:37 | 显示全部楼层
    我怎么没用到 include 和 wp_insert_post ???
    你不用循环吗?
    回复

    使用道具 举报

    253

    主题

    426

    回帖

    1635

    积分

    金牌会员

    积分
    1635
     楼主| 发表于 2019-1-15 13:57:02 | 显示全部楼层

    yonlee 发表于 2019-1-15 13:42

    我怎么没用到 include 和 wp_insert_post ???
    你不用循环吗?

    不是插件和主题,是调用wordpress发表日志。
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-4-22 21:29 , Processed in 0.015825 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表