Comments

thanks alot. i have been pulling my hair out trying to work out what the hell was happening to prevent my loops paginating, and now that i know it was just 'paged' => $paged i wanta punch the wall for the time I’ve wasted trying to fix it…. 🙂 but at least i have hair.

thanks alot.

Thanks for the explanation of pagination and the relationship to my_query / wp_query. However, I got thrown an error when trying to set “$wp_query = null;“… removing that bit let it work, but I’m seeing some duplicate posts being pulled… thanks for the start though!

Thank you sooooooooo much! I’m impressed by the explanation you did and the great work! It was so hard for me to do it myself, so you rescued me from suffering all night long!

Darrin, Thanks for that tutorial. I work quite a lot with wordpress for various sites and have found ways to solve almost any problem. But honestly, yours is the only tutorial I could find to fix the pagination on a page template. Tried it and it simply worked like a charm…

Really well done! Thanks!
Philipp

@Philipp No problem! The great thing about this way is you can actually have multiple pagination sections on the same page (provided it’s coded right). I tried it once and it worked well, but really needed to be implemented in an Ajax call.

Just wanted to say this is the first tutorial of the dozens I’ve come across, that thoroughly and clearly explains custom queries, plus navigation, so thank you for putting it together!

I cant explain how useful this tut was compared to the barrage of other tuts out there on the same topic…Really well thought out and explained.

Just one quick question – When you note on page 3 that “since we’re using the $wp_query object and not our own custom one” that you can still use WordPress’ standard loop syntax…..I was just curious if you could extrapolate on this a bit — ie. What are the benefits of using a custom “query object”, and what must be done to the loop in order to take advantage of them?….

Best,
SB

@Shaun: Using custom query objects ($my_query = new WP_Query) allows you to have multiple content loops on a single page. Digging Into WordPress has a good article here that goes into more detail: 4 Ways to Loop with WordPress.

To respond to this part though: “and what must be done to the loop in order to take advantage of them” Nothing is done to the Loop, the Loop is built from the query object. Creating your own query object allows you to specifically define what will display on the page.

Here’s a good resource as well: When should you use WP_Query vs query_posts() vs get_posts()?

I should also note, when running a new instantiation of WP_Query, always reset it by calling wp_reset_query() at the end of your script.

– db

Appreciate the additional info, thanks!

1. So what is nessecary to do in the loop if I were to use say $events_only_query = new WP_Query($args); vs. wordpress’ $wp_query = new WP_Query($args); ? I notice paging is suddenly unavailable when using a custom object of my own for some reason…

2. Additionally, one thing I cant seem to wrap my head around from the extra resources you cited, is what if I decide to have multiple loops on the same page but not in the same loop? ie. Main custom loop that queries only one post type or category in the “main content area”, then say an additional custom loop in the “sidebar” grabbing a custom post type and showing its content, and then say yet another in the “footer” for a featured post?…….

Further, what I’m confused about is since these loops are in their own respective templates and intentionally being displayed in different places around the site, do the same practices still apply such as: Starting with either get_posts or query_posts for the main loop and using WP_Query for any additional loops such as the sidebar or footer?

Hope that makes sense!? And thanks again for the useful info.

PS – I just realized I have been partially asking my first question with the wrong terms after reviewing your first response since Im calling the “name” I define to $wp_query such as $events_only_query a “custom object”….just to clarify, I guess what Im really asking in the first part of my question is what are the benefits of using your own assigned name vs just $wp_query?

Comments are closed.