how to make a WP_Query by A or B?

  • Unknown's avatar

    Hello, I tried to find out by myself the answer to this but i found no post about it… or entry in the forum.

    I have to retrieve a list of posts which must belog to a certain category OR to a certain custom post type.

    For example, i have a normal post categorized as NEWS (cat_ID = 3) (N1) and i have a custom post type called “interviews”, with for example 3 posts (I1, I2, I3) and lets say other custom post type called “OTHER” with 2 posts, O1, O2

    When i query for the posts, i want to get in the lists /array returned: N1, I1, I2, I3, O1, O2 (irrelevant order…)

    I am trying it through WP_Query but i have no luck… My code snippet is:


    $args = array(
    'post_type' => array('interviews', 'other')
    ,'cat' => 3
    ,'posts_per_page' => self::limit_posts
    ,'orderby'=>'date'
    ,'order'=>'DESC'
    // ,'meta_key'=>'_thumbnail_id'
    // ,'meta_compare'=>'>='
    // ,'meta_value'=>'1'
    );

    $posts_custom = new WP_Query($args);
    var_dump( $posts_custom );die;

    And i get nothing… if i query only by post_type or only by category, i do get results…

    how can i make that “OR” query?

    I hope i made myself understood ^_^and thank you in advance

  • The topic ‘how to make a WP_Query by A or B?’ is closed to new replies.