I'm working on a project where I need display 2 post from one category and also I need to put another loop between this post post to display random list of post from other category. Easiest way to do so is to create 3 queries, but when I created 2 queries for one category, but here I got problem one loop breaks and display both posts, second works fine. I used offset parameter for second query but it doesn't work.
<?php
$first_query_args = array(
'category_name' => 'first-category',
'tag' => 'special-tag',
'post_per_page' => 1,
);
$first_query = new WP_Query( $first_query_args );
if ( $first_query->have_posts() ) : while ( $first_query->have_posts() ) : $first_query->the_post();
// First query stuff goes here
endwhile; endif;
wp_reset_query();
// Query for Random posts
$query_for_random_args = array(
'category_name' => 'cat-for-rand',
'post_per_page' => 3,
'orderby' => 'rand',
);
$query_for_random = new WP_Query( $query_for_random_args );
if ( $query_for_random->have_posts() ) :
?>
<ul>
<?php while ( $query_for_random->have_posts() ) : $query_for_random->the_post(); ?>
<li>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'list-image' ); ?></a>
<a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a>
</li>
<?php } endwhile; ?>
</ul>
<?php endif; wp_reset_query(); ?>
<?php
$second_query_args = array(
'category_name' => 'first-category',
'tag' => 'special-tag',
'offset' => 1,
'post_per_page' => 1,
);
$second_query = new WP_Query( $second_query_args );
if ( $second->have_posts() ) : while ( $second_query->have_posts() ) : $second_query->the_post();
// Second query stuff goes here
endwhile; endif;
?>
( This code What I use for those loops )
Any ideas how can I solve this problem? or how can I use 2 queries for similar task?
Cheers
George