以下代码返回一个空数组,即使我知道有些帖子具有给定的$args = array(
'post_parent' => 211167,
);
$posts_array = get_posts( $args );
$data->subfolder_count = sizeof( $posts_array );
id:
(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 |
+----+------------+-----------+-----------+-------------+
+----+------------+-----------+-----------+-------------+
我尝试过使用cli并获得相同的结果
string.Trim
如果你能告诉我自己做错了什么,我会很感激。
答案 0 :(得分:0)
get_posts()
默认仅提取帖子类型为post
的帖子。由于您编辑了post_type
我认为它是自定义帖子类型。在参数中添加正确的post_type
。
答案 1 :(得分:0)
看起来需要post_type
。我将代码更改为包含post_type
而不是post_parent
,并获得了我想要的结果。