• I know that I can perform a query for multiple post types by using in the query arguments:

    post_type = array(‘post’, ‘custom_post_type’) etc etc.

    Is there a way to combine different arguments though, for different post types in one query?

    Specifically, I have the custom post type “event” which has a “_end_ts” meta value which is a timestamp of the event end time and I have the following queries:

    $args_normal_qry = array(
    'post_type' => $'post',
    'orderby' =>'date',
    'order' => 'DESC',
    'post_status' => 'publish');
    
    $normal query = new WP_Query( $args_normal_qry );

    and

    $args_event_qry = array( 'post_type' => 'event',
    'post_status' =>'publish',
    'meta_query' => array(
    'key' => '_end_ts',
    'value' =>(current_time('timestamp') - 14400),
    'compare' => '>=',
    'type'=>'numeric' ),
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_key' => '_end_ts',
    'meta_value' => (current_time('timestamp')-14400),
    'meta_value_num' => (current_time('timestamp')-14400),
    'meta_compare' => '>=' );
    
    $event_query = new WP_Query($args_event_qry );

    I wish to display BOTH normal posts AND event posts, retrieved by the two queries (leave out the “events” that have “ended” 4 hours ago – this is performed by the arguments in the second query above).

    Is there a way to do that?

    Thanks for any info – tips – guidance.

The topic ‘One Query with different arguments per post type’ is closed to new replies.