Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active December 11, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/4548117 to your computer and use it in GitHub Desktop.
Save billerickson/4548117 to your computer and use it in GitHub Desktop.
Query arguments in the grid loop are now ignored.  This is because most uses of the grid
loop were for displaying the main query (ex: blog posts on your blog page, category page...),
and providing query arguments like 'posts_per_page' lead to 404 errors. Unfortunately this also
means you can't use it for custom loops, like you were doing.
Take a look at the staff_do_grid_loop() function here: https://gist.github.com/4548000
(I wrote it directly in the Gist so can't guarantee it's perfect).
<ol>
<li>First you specify your query arguments, then create a new loop like this: $loop = new WP_Query ($args );</li>
<li>Then you loop through this: if( $loop-&gt;have_posts() ): while( $loop-&gt;have_posts() ): $loop-&gt;the_post();</li>
<li>Then you specify the markup for each post. I'm wrapping them in a div with either a class of "one-half first" or "one-half" depending on the post count. Inside this div, I have the title hyperlinked and the excerpt.</li>
<li>Finally, once you're done with your loop run wp_reset_postdata(); . This reverts the $post object back to the original query's.</li>
</ol>
For more information:
<a href="http://www.billerickson.net/custom-wordpress-queries/">Custom WordPress Queries</a> (for custom queries)
<a href="http://www.billerickson.net/customize-the-wordpress-query/">Customizing the WordPress Query</a> (for the main page query)
<a href="http://www.billerickson.net/a-better-and-easier-grid-loop/">A better, easier grid loop</a> (this is for the main query, but the example I provided in this post takes the idea and applies it to a custom query)
&nbsp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment