Handling Queries

For using Archive Types, the main building block is query. The query works just like the normal WordPress queries, the details about which can be found at WordPress Codex.

In this plugin, there are two ways of specifying queries for archive types

  1. At creation, In the specification of Archive Types
  2. At Runtime, using attribute “query” in the shortcode.

At creation, In the specification of Archive Types

For specifying the query at the time of creation gives you an option to specify the default output of the archive. In This for instance you can use query


which would output posts in uncategorized category.

But it doesn’t specify the number of posts you want to specify in that archive. Lets say you want to add another condition in the query for limiting the number of posts to 3. So the query becomes


So for concatenating the variable & is used.


Details for creating more custom queries is given on WordPress Codex at http://codex.wordpress.org/Function_Reference/query_posts


At Runtime, using attribute “query” in the shortcode.

You can also change the query on runtime, this can be done by adding attribute query to default short-code used for accessing the archive.

For example, lets say there is an archive named venus having default query


 hence displays 5 posts from post type News.

Now if you want to use the same archive at a different place but for post type photos, then all you need to do is add the attribute query=”post_type=photos” in the shortcode call.

Hence the final shortcode becomes:

[xydac_archive  query="post_type=photos"]venus[/xydac_archive]

Known Issue

Currently attributes involving use of arrays are not directly supported, Though you could hack into using arrays in query string like this

Original query (From Codex) gives post from category 1 and 3 with two post per page:

category__and => array(1,3), 'posts_per_page' => 2

Converted Query


5 thoughts on “Handling Queries”

Leave a Reply

Your email address will not be published. Required fields are marked *