Tag: WP_Query
-
Use of mysql_connect in WordPress
-
WP_Query::get_posts()
Every call to retrieve posts goes through WP_Query, and the bulk of the logic is in the method get_posts. Here’s some potentially useful information about the current state of what is arguably the most important function in WordPress. WP_Query::get_posts is 890 lines long, and has a cyclomatic complexity of 256. A good cyclomatic complexity is ~2-6,…
-
Alternative Post Loops
We all know the standard post loop in every template, but what if we did something slightly different? Lets begin with the standard main loop we all know: View the code on Gist. There’s a lot of boilerplate there, what if we could reduce it down? Lets try using a feature of PHP 5 called…
-
Getting From URL to Template
So you load a page on a WordPress site. How did it know to load the page template? How did it know it was a page and not a category listing? Is it hardcoded somewhere? To begin with lets list out what happens, then we’ll explain each step in basic terms: .htaccess rules pass the URL…