Quantcast
Viewing all articles
Browse latest Browse all 4

WordPress Using rewind_posts() to show multiple Custom Queries

I searched for a while on how to do this and finally think I figured it out but it still needs to be tweaked.
First you need to create your custom queries, I have created 2 here which pull from different categories.

I searched for a while on how to do this and finally think I figured it out but it still needs to be tweaked.
First you need to create your custom queries, I have created 2 here which pull from different categories.

<?php $my_query = new WP_Query('category_name=~Welcome~'); ?>

<?php $my_query2 = new WP_Query('category_name=~Site Updates~'); ?>

Replace

if (have_posts()) {while (have_posts()) {the_post();?>

With

if (have_posts()) {while ($my_query->have_posts()) {$my_query->the_post();?>

After the loop is finished (somewhere around the endif / or equivalent) Add

<?php rewind_posts(); ?>

Then copy and paste your entire loop but modify your initial query so it now reads your second custom query.


Viewing all articles
Browse latest Browse all 4

Trending Articles