We hope you enjoyed the ride. In this final part, we're going to go through what we learned and close the curtains.
This was the introduction to the series by Rachel. In this part, we learned:
WP_Queryis in simple terms and a simple example
WP_Query, and why we should use it over other methods to create custom queries
WP_Querythat we should know about
The second part was about creating a loop with the
WP_Query class, also written by Rachel. In this part, we learned:
In this part, written by yours truly, we went over 13 functions that interact with
WP_Query, making it easier to work with it. The functions were:
get_query_var(), which gets public query variables
query_posts(), which alters the main loop and is a bad, very bad function
get_post(), which gets a simple post to work with
get_posts(), which gets posts and returns them in an array
get_pages(), which gets pages in the same fashion
have_posts(), which is a Conditional Tag that returns
TRUEif there are posts returned in the query
the_post(), which turns the cogs in the loop
setup_postdata(), which sets up the global
rewind_posts(), which clears the current loop
wp_reset_postdata(), which resets the global
wp_reset_query(), which resets the whole query
is_main_query(), which checks if the current query is the main query (and is another Conditional Tag)
in_the_loop(), which checks if we're in the loop (and is yet another Conditional Tag)
This part that I wrote was both annoying and rewarding to write about. It was annoying because it took way more research time, but it was very rewarding because, well, I learned so much. (Pro learning tip: Write a tutorial on a subject that you know little about!)
WP_Query-related filter was (in some way) about the SQL commands that run the query—most of them filter the different clauses like
DISTINCT. The three actions, on the other hand, serve different purposes:
pre_get_postsaction interferes with the query before it's run.
parse_queryaction handles the parsing of the query.
the_postaction modifies the post object.
In this part that I wrote, we went over the properties and methods of the
WP_Query class. ("Properties" and "methods" are merely "variables" and "functions" within a PHP class.) The properties (variables) we learned about were:
$is_, which work like Conditional Tags
And the methods (functions) were:
In the next seven parts, Rachel did a fantastic job explaining all of the arguments that we can use with the
WP_Query class, with little examples:
In this part, I took the liberty of going through various examples using the
WP_Query class and its related functions. (I also gave a quick example to remind you how to create a loop with
WP_Query.) The examples were about:
I have to admit, this was the most fun part that I worked on!
This part, written by Rachel, tells us about combining the
WP_Query class with the main query. It's a very intriguing subject but I have to give some spoilers here—in this part, Rachel gave three great examples:
Did you know that there are classes that work like the
WP_Query class to help
WP_Query? In the following parts, Rachel and I talked about:
WP_User_Queryin part 15
WP_Comment_Queryin part 16
WP_Date_Queryin part 17
In this part, Rachel talked about the improvements to the query system of WordPress in version 4.1—like nested queries, comment parameters and general bug fixing. It's a gentle part, a light read before the end.
As the Oracle said in The Matrix Revolutions: Everything that has a beginning has an end.
It was a long ride, and as I said in the beginning, it's one of the longest series in the history of Tuts+. I joined forces with Rachel McCollin, one of the best instructors in Tuts+, and we're both proud to be the ones that wrote the longest, the most comprehensive and the most epic tutorial series on the
WP_Query class and its companions.
We worked very hard on the series, and we really hope that you enjoyed every bit of it. If you learned something new in this 19-part series, then we're happy that we've done a good job.
If you have any comments about this series, don't hesitate to share your thoughts in the Comments section below. And, as always, if you liked the series, don't forget to share this final part with your friends as an index.