So I have a dynamic loop which is affected by a query sting in the URL..

For example I have 3 categories and when they click the category it just adds a query to the URL:

<a href="?view=dogs">Dogs</a>
<a href="?view=cats">Cats</a>
<a href="?view=other">Other</a>

and then my custom loop will pull the query values to show relative posts

$args = array('post_type' => 'animals', 'posts_per_page' => 4, 'category' => $queryString);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query($args);

I then have my pagination code which is working as expected but it doesn't change the posts.. I have a feeling its because of the url structure.. http://example.com/animals/page/2/?view=cats

any help from you awesome people!

  • You already have query vars(they're just masked by the pretty URL), use & in place of ? .. – t31os Feb 11 '14 at 16:22

It looks like the paged variable isn't being added to the query arguments. This should work:

$paged = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
$args = array(
    'post_type' => 'animals', 
    'posts_per_page' => 4, 
    'category' => $queryString,
    'paged' => $paged
$wp_query = new WP_Query( $args );

Also, as a note, $wp_query is a WordPress global variable. It would be safer to use a different name like $my_query, $custom_query, $steve, etc.

  • This has solved my problem! Thank you! Such a simple thing I missed! – Levi Cole Feb 12 '14 at 8:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.