query_post parameters in for wordpress posts

  1.  To get a specific post using post id
    use: “p=101”.
  2. To get a specific page using page id
    use: “page_id=101”.
  3.  To get all posts from a specific post category use id of that category in query posts.
    Use: “cat=5”
  4. To get all posts from a specific post type use slug of that query post. Eg post type “Products” with slug “product”
    Use: “post_type=product”
  5.  To get all posts witha specific tag . Eg: with tag “wordpress”
    Use: “tag=wordpress”
  6. You can also include category here. Posts with a specific category and tag
    Eg: query_posts( ‘cat=4&tag=wordpress’ );

You can use following inside querypost to restrict the displaying posts with above parameters:

  1. Number of posts: “showposts”, specify the number of posts here
    Eg: query_posts( ‘cat=4&showposts=4’ );
  2.  order: order of posts displaying, Ascending, or Descending.
    query_posts(order=ASC); for ascending order.
    query_posts(order=DESC) for descending order.

Default it will be descending order.

Displaying posts based on post type taxonomies:

$args = array(
‘post_type’ => ‘imageslider’,   // Post type
‘showposts’ =>4,     // Number of sliders
‘tax_query’ => array(
‘taxonomy’ => ‘imagecategories’,   // Taxonomy name
‘field’ => ‘id’,
‘terms’ => $postTaxonomy,


Leave a Reply

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