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'),
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745504082a4630548.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