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')
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.wp-load,php
? Is this not running inside of WP somewhere?'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.