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条)

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面