admin管理员组文章数量:1430171
I am building a custom WordPress function/plugin that uses get_posts. The following code returns an empy array. I have included wp-load.php in my script. Is there something else I am missing?
$args = array(
"posts_per_page" => -1,
"paged" => 0,
"orderby" => "post_date",
"order" => "DESC",
"post_type" => "carellcars, ccf, attachment",
"post_status" => "publish, inherit",
"post_author" => "2"
);
$posts_array = get_posts($args);
print_r($posts_array);
die;
If I use arrays for post_type and _status the array is not populated, but if I use single values for post_type and _status the array is populated?
Not populated:
$args2 = array(
'posts_per_page' => -1,
'paged' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => array('carellcars', 'ccf', 'attachment'),
'post_status' => array('publish', 'inherit')
);
Populated:
$args2 = array(
'posts_per_page' => -1,
'paged' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'carellcars',
'post_status' => 'publish'
);
Update, removing "ccf" post type produces results, but I do have a ccf post_type and would like to include them. Any ideas?
'post_type' => array('carellcars', 'attachment'),
'post_status' => array('publish', 'inherit')
I am building a custom WordPress function/plugin that uses get_posts. The following code returns an empy array. I have included wp-load.php in my script. Is there something else I am missing?
$args = array(
"posts_per_page" => -1,
"paged" => 0,
"orderby" => "post_date",
"order" => "DESC",
"post_type" => "carellcars, ccf, attachment",
"post_status" => "publish, inherit",
"post_author" => "2"
);
$posts_array = get_posts($args);
print_r($posts_array);
die;
If I use arrays for post_type and _status the array is not populated, but if I use single values for post_type and _status the array is populated?
Not populated:
$args2 = array(
'posts_per_page' => -1,
'paged' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => array('carellcars', 'ccf', 'attachment'),
'post_status' => array('publish', 'inherit')
);
Populated:
$args2 = array(
'posts_per_page' => -1,
'paged' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'carellcars',
'post_status' => 'publish'
);
Update, removing "ccf" post type produces results, but I do have a ccf post_type and would like to include them. Any ideas?
'post_type' => array('carellcars', 'attachment'),
'post_status' => array('publish', 'inherit')
Share
Improve this question
edited May 11, 2019 at 0:01
Jobbie Daddy
asked May 9, 2019 at 16:03
Jobbie DaddyJobbie Daddy
771 silver badge8 bronze badges
18
|
Show 13 more comments
1 Answer
Reset to default 2Try
"post_type" => array('carellcars', 'ccf', 'attachment'),
本文标签: get postsgetposts returning empty array
版权声明:本文标题:get posts - get_posts returning empty array 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745504082a2661164.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
meta_key
andmeta_value
entirely. What you're asking for here is for all posts that have an empty meta key with an empty meta value actually saved. – WebElaine Commented May 9, 2019 at 16:06wp-load,php
? Is this not running inside of WP somewhere? – WebElaine Commented May 9, 2019 at 18:36'carellcars'
, try witharray('carellcars')
, next witharray('carellcars', 'page')
orarray('carellcars', 'post')
. As I wrote earlier, when the post type is an array, I can see the results. I do not know why it is different with you. The trial and error method remains. – nmr Commented May 10, 2019 at 18:20