get_posts by post_parent returns empty array

James Laughlin

The following code returns an empty array even though I know there are posts that have the given post_parent id:

$args = array(
    'post_parent'      => 211167,
);

$posts_array = get_posts( $args ); 
$data->subfolder_count = sizeof( $posts_array );

I have tried using the cli and gotten the same result

(12:05:29) mu-plugins/$ wp post get 211169
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| ID                    | 211169                               |
| post_author           | 12449                                |
| post_date             | 2016-08-14 11:21:26                  |
| post_date_gmt         | 2016-08-14 16:21:26                  |
| post_content          |                                      |
| post_title            | SubFolder Two                        |
| post_excerpt          |                                      |
| post_status           | publish                              |
| comment_status        | closed                               |
| ping_status           | closed                               |
| post_password         |                                      |
| post_name             | subfolder-two                        |
| to_ping               |                                      |
| pinged                |                                      |
| post_modified         | 2016-08-14 11:21:26                  |
| post_modified_gmt     | 2016-08-14 16:21:26                  |
| post_content_filtered |                                      |
| post_parent           | 211167                               |
| guid                  | [redacted]                           |
| menu_order            | 0                                    |
| post_type             | [redacted]                           |
| post_mime_type        |                                      |
| comment_count         | 0                                    |
+-----------------------+--------------------------------------+

(12:05:40) mu-plugins/$ wp post list --post_parent=211167
+----+------------+-----------+-----------+-------------+
| ID | post_title | post_name | post_date | post_status |
+----+------------+-----------+-----------+-------------+
+----+------------+-----------+-----------+-------------+

If you can tell me what I'm doing wrong I'd appreciate it.

Gerald Schneider

get_posts() fetches only posts with the post type post by default. Since you redacted the post_type I assume it's a custom post type. Add the correct post_type to your arguments.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

In Wordpress, post_parent returns 0

From Dev

Wordpress WP_Query/get_posts where post_title equals returns all results

From Dev

WordPress get post using post_parent field

From Dev

Wordpress get_posts() post limit

From Dev

Retrieve post taxonomy inside get_posts()

From Dev

Get xtick labels in matplotlib returns empty array?

From Dev

wordpress, why return $this->get_posts(); returns values?

From Dev

mapPartitions returns empty array

From Dev

Aggregate returns empty array

From Dev

Retrofit returns an empty array

From Dev

Array returns empty

From Dev

$('div'); returns an empty array

From Dev

PFQuery returns Empty Array

From Dev

NSUserDefaults returns empty array

From Dev

postman returns empty array

From Dev

Multiple Array keys in WordPress get_posts Function

From Dev

get_posts using a multidimensional array and 2 meta keys

From Dev

Combine get_posts loop with another array and randomise sort by date

From Dev

Array concat returns empty array

From Dev

"GET"ting AngularJS resource in MSIE 9 returns empty array

From Dev

WebdriverJS : driver.manage().logs().get('browser') returns empty array

From Dev

Wordpress get_terms returns empty array for custom taxonomy

From Dev

Items: Get item revision difference returns empty array

From Dev

Loop posts excerpt returns empty

From Dev

PDO fetchAll() returns empty array

From Dev

Instagram API returns empty array

From Dev

ABAddressBookCopyPeopleWithName returns empty array on Simulator

From Dev

PDO returns empty array as result

From Dev

wxGrid GetSelectedCells returns empty array