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.
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.
Comments