Mastering WP_Query: An Introduction
read more
Categories

Mastering WP_Query: An Introduction


By default, WordPress will run a query on each page that your site displays, the nature of which will be determined by the type of page being viewed. So if a static page is being viewed, WordPress runs a query to display the page with the relevant ID, while if an archive page is being viewed, the query will retrieve all posts in that archive.

But sometimes you want to do things a bit differently. Either in your page’s main content or elsewhere on the page (such as in the sidebar or footer), you might want to display some specific content which isn’t output by the standard query.

The great news is that WordPress makes that possible with the WP_Query class. This class provides you with a large number of parameters you can use to define what content you want to output (which needn’t be limited to posts) and then write a loop which will show the content exactly as you want to.

In this ten-part series on Mastering WP_Query, Baris Unver and I will take you through the ins and outs of WP_Query so that once you’ve completed the series, you’ll be able to use it in a variety of scenarios and fine tune the way WordPress queries the data in your site’s database.