This shortcode is used to get list of posts based various criteria. aw2_query_posts behind the scene uses either get_posts function or WP_Query class depending on the query_type parameter. It returns a collection, which can be accessed using aw2_collection and aw2_loop. We pass arguments to aw2_query_posts using JSON value, for which attributes are exactly same as that of WP_Query.


  • id:
    This is used to uniquely identify query result, which can be later accessing this ID. It defaults to ‘default_collection’
  • main:
    if only one value is required from the collection then you can directly put the parameters of aw2_collection to get that value.
  • part:
    main | tax_query | meta_query

    It allows us to break complex queries into parts. It gives us ability to add or remove parts of a query based on conditions. When part is main it destroys all existing parts and creates a new query, so it is important that when you are breaking a query into parts, part=main is first. Part tax_query indicates that JSON value is for running taxonomy query, similarly part meta_query indicates that JSON value is to be used for creating meta query.If parts is not used, then query executes immediately.
  • relation:
    AND | OR

    It defaults to ‘AND’. It is used in taxonomy and meta query to define the relationship. See Taxonomy Query for details
  • request_taxonomy:
    It is comma separated string of taxonomy slugs which can be used to build a series of taxonomy conditions based on request parameters. It is equivalent to writing ‘AND’ relation based tax_query for each taxonomy. It looks into Request object to find “taxonomy=terms” pairs. It comes in handy when we are doing filtering of data based on taxonomies.
  • param_taxonomy:
    It is similar to request_taxonomy, with only difference being it uses param object instead of request object.
  • query_type:
    get_posts | get_pages | wp_query

    It defaults to ‘get_posts’. You should use wp_query, if you need use pagination with your query.
  • run:
    It defaults to ‘false’. If set to true, it will run a query which is in parts. It is required for execution of query if they have been split into parts. You don’t need to set run, if parts is not used.
You can use all the conditional parameters available with aw2_if directly to execute parts based on conditions.

p.s remove the space between “[” and “aw2” in the examples below, they have been added to avoid their execution on this page.


This is most common usage of aw2_query_posts, it will put the results directly into ID default_collection

Using parts to split complex queries using ID, if ID is not specified it will assume default_collection.

Using request_taxonomy along with aw2_query_posts