Support » Fixing WordPress » query to get posts which have multiple categories (And relation doesn’t work)

  • Hello,
    I want to show posts which have some specific categories for example have categories (a,b,and c). I wrote the query for it but And relation doesn’t work and it only displays posts of the first category I write. I need it a lot, thanks for helping:)
    <?php
    $args2 = array(
    ‘post_type’ => ‘post’ ,
    ‘orderby’ => ‘date’ ,
    ‘order’ => ‘DESC’ ,
    ‘posts_per_page’ => 6,
    ‘relation’ => ‘And’,
    ‘category_name’=>’a’,’b’,’c’,
    ‘paged’ => get_query_var(‘paged’),
    ‘post_parent’ => $parent
    );
    $q = new WP_Query($args2);
    if ( $q->have_posts() ) {
    while ( $q->have_posts() ) {
    $q->the_post();
    echo the_title();
    }
    }

    ?>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘query to get posts which have multiple categories (And relation doesn’t work)’ is closed to new replies.