duan0403788996 2016-04-13 21:34
浏览 37
已采纳

在查找某个post_type时,get_posts()不会返回帖子

I currently have the same args to look for a certain post:

$page = 0;

$args = array(
    "posts_per_page" => 10,
    "offset" => $page * 10,
    "post_type" => "graven",
    "post_status" => "publish"
);

$posts = get_posts($args);
var_dump($posts);

This properly returns the 10 first posts of this type, ordered by date. Now, there's another custom post type (made using the Pods framework, pods.io), which has a different name, other than that, should be quite the same. The only difference I should be using in my queries is changing the post_type to begraafplaats and set the post_status to draft, however, this results in an empty array to be returned. I know the ID of one of these posts, so using get_post(<the id>) I queried the post, and got the result as I expected.

This gives me the following output:

WP_Post Object
(
    [ID] => 3935
    [post_author] => 1
    [post_date] => 2015-08-21 04:25:16
    [post_date_gmt] => 0000-00-00 00:00:00
    [post_content] => 
    [post_title] => R.K. Begraafplaats St. Theresiakerk (Eindhoven)
    [post_excerpt] => 
    [post_status] => draft
    [comment_status] => closed
    [ping_status] => closed
    [post_password] => 
    [post_name] => 
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2015-08-21 04:25:16
    [post_modified_gmt] => 2015-08-21 04:25:16
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://example.com/?post_type=begraafplaats&p=3935
    [menu_order] => 0
    [post_type] => begraafplaats
    [post_mime_type] => 
    [comment_count] => 0
    [filter] => raw
)

As you can see, the post_type returned is the same I used in my $args array, and the post type is draft, as expected. Yet, it doesn't seem to get me any results.

Would there be a reasonable explanation of why this wouldn't work?

  • 写回答

2条回答 默认 最新

  • dongwei3172 2016-04-15 23:38
    关注

    I have managed to resolve the issue using bare MySQL queries using $wpdb. It's not an elegant solution, however, I do have all the info I need now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP