This question already has an answer here:

This following produces an empty array:

$args2 = array(
    'posts_per_page' => -1,
    'paged'          => 0,
    'orderby'        => 'post_date',
    'order'          => 'DESC',
    'post_type'      => array( 'carellcars', 'ccf', 'attachment' ),
    'post_status'    => array( 'publish', 'inherit' )

$posts_array2 = get_posts($args2); 

Changing the post_type and post_status to a single string (only one post_type, one post_status) produces results. Is my syntax wrong? Or how can I query multiple post types and post states at once?

marked as duplicate by fuxia May 10 at 18:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What function gets $arg2 passed to? get_posts()? WP_Query? Where exactly are you executing this code? – leymannx May 10 at 17:53
  • I'm executing the code in a php script inside public_html directory. $posts_array2 = get_posts($args2); – Jobbie Daddy May 10 at 17:56
  • Can you maybe paste all the relevant parts in your question? – leymannx May 10 at 18:01
  • Ah sorry, no need. You already said, single values work. So it's not your script. – leymannx May 10 at 18:06
  • My development environment is WordPress version 4.4.11 . Do you know if that supports array values in the arguments? – Jobbie Daddy May 10 at 18:10

Browse other questions tagged or ask your own question.