Ruben Rutten Ruben Rutten - 1 year ago 112
PHP Question

get_posts() doesn't return posts when looking for a certain post_type

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

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,, 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
and set the
, 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] =>
[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
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?

Answer Source

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.