Display posts in custom query with one post form
-
I am trying to first display four posts with post-format-aside (all assigned to current tag) and then display the “real” archive (exclude post-format-aside) for the specific tag.
Right now I am using a function to exclude post format-aside from the main query:add_action('pre_get_posts', 'keyl_get_emp_posts'); function keyl_get_emp_posts($query) { if (is_tag()) { if ($query->is_main_query()) $taxq = array( 'tag' => $current_tag, array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside' ), 'operator' => 'NOT IN' ) ); $query->set('tax_query',$taxq); } }Than I am trying to display the custom query with only post-format-aside with
<div class="row"> <?php $current_tag = single_tag_title("", false); $args = array( 'posts_per_page' => 4, 'tag' => $current_tag, 'post_type' => array('post', 'renvoeringsdamm'), 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside' ) ) ) ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); ?> <div class="col-sm-3 col-xs-6"> <?php get_template_part( 'content', get_post_format() ); ?> </div> <?php } wp_reset_postdata(); } ?> </div>But the special query for only post-format-aside is displaying post from all types of post-formats… So my question is really, what is wrong with what I have done so far!..
The topic ‘Display posts in custom query with one post form’ is closed to new replies.