Computing Magazine

Query Posts in WordPress

Posted on the 29 April 2014 by Akahgy


Querying through the posts can be useful for creating special container pages. Returning the posts you require is only a matter of using the right attributes.


A query in WordPress looks like a series of GET variables:


This will return all posts that are in category 7, and will order them alphabetically.

WordPress offers also other functions that help query for the right posts:

have_posts(); – boolean, determines if the query was successful

the_post(); – focuses on one post from the iteration, allows different operations

get_the_category(); – returns the category of the post

get_the_title(); – returns the title of the focused post

More example under:

Back to Featured Articles on Logo Paperblog