WP Query – All Parameter

<h2>WP Query</h2>

<?php
/**
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/query.php
*/

$args = array(

//////Author Parameters – Show posts associated with certain author.
author‘ => ‘1,2,3,
author_name‘ => ‘samplename‘,

//////Category Parameters – Show posts associated with certain categories.
cat‘ => 5,//(int) – use category id.
category_name‘ => ‘staff‘, ‘news‘,
‘category__and’ => array( 2, 6 ),
‘category__in’ => array( 2, 6 ),
‘category__not_in’ => array( 2, 6 ),

//////Tag Parameters – Show posts associated with certain tags.
tag‘ => ‘cooking’,
‘tag_id’ => 5,
‘tag__and’ => array( 2, 6),
‘tag__in’ => array( 2, 6),
‘tag__not_in’ => array( 2, 6),
‘tag_slug__and’ => array( ‘red’, ‘blue’),
‘tag_slug__in’ => array( ‘red’, ‘blue’),

//////Taxonomy Parameters – Show posts associated with certain taxonomy.
//Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)
//This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.
‘tax_query’ => array(

relation‘ => ‘AND’,
array(
‘taxonomy’ => ‘color’,
‘field’ => ‘slug’,
‘terms’ => array( ‘red’, ‘blue’ ),
‘include_children’ => true,
‘operator’ => ‘IN’

),
array(

‘taxonomy’ => ‘actor’,
‘field’ => ‘id’,
‘terms’ => array( 103, 115, 206 ),
‘include_children’ => false,
‘operator’ => ‘NOT IN’

)
),

//////Post & Page Parameters – Display content based on post and page parameters.
‘p’ => 1,
‘name’ => ‘hello-world’,
‘page_id’ => 1,
‘pagename’ => ‘sample-page’,
‘pagename’ => ‘contact_us/canada’,
‘post_parent’ => 1,
‘post__in’ => array(1,2,3),
‘post__not_in’ => array(1,2,3),
//NOTE: you cannot combine ‘post__in’ and ‘post__not_in’ in the same query

//////Type & Status Parameters – Show posts associated with certain type or status.
‘post_type’ => array(

post‘,
page‘,
revision‘,
attachment‘,
my-post-type’,

),
‘post_status’ => array(

publish‘,
pending‘,
draft‘,
‘auto-draft’,
future‘,
private‘,
inherit‘,
trash

),

//NOTE: The ‘any’ keyword available to both post_type and post_status queries cannot be used within an array.
‘post_type’ => ‘any’,
‘post_status’ => ‘any’,

//////Pagination Parameters
‘posts_per_page’ => 10,
‘posts_per_archive_page’ => 10,
nopaging‘ => false,
paged‘ => get_query_var(paged‘),
//NOTE: Use get_query_var(‘page’); if you want your query to work in a Page template that you’ve set as your static front page. The query variable ‘page’ holds the pagenumber for a single paginated Post or Page that includes the <!–nextpage–> Quicktag in the post content.

//////Offset Parameter
offset‘ => 3,

//////Order & Orderby Parameters – Sort retrieved posts.
order‘ => ‘DESC’,
orderby‘ => ‘date’,

//////Sticky Post Parameters – Show Sticky Posts or ignore them.
‘ignore_sticky_posts’ => false, //(bool) – ignore sticky posts or not. Default value is false, don’t ignore. Ignore/excludsticky posts being included at the beginning of posts returned, but the sticky post will still be returned in the natural order othat list of posts returned.
//NOTE: For more info on sticky post queries see: http://codex.wordpress.org/Class_Reference/WP_Query#Sticky_Post_Parameters

//////Time Parameters – Show posts associated with a certain time period.
year‘ => 2012,
monthnum‘ => 3,
w‘ => 25,
day‘ => 17,
hour‘ => 13,
minute‘ => 19,
second‘ => 30,

//////Custom Field Parameters – Show posts associated with a certain custom field.
‘meta_key’ => ‘key’,
‘meta_value’ => ‘value’,
‘meta_value_num’ => 10,
‘meta_compare’ => ‘=’,
‘meta_query’ => array(
array(

key‘ => ‘color’,
value‘ => ‘blue’
type‘ => ‘CHAR’,
compare‘ => ‘=’

),
array(

key‘ => ‘price’,
value‘ => array( 1,200 ),
compare‘ => ‘NOT LIKE’

)

//////Permission Parameters – Display published posts, as well as private posts, if the user has the appropriate capability:
perm‘ => ‘readable’ //(string) Possible values are ‘readable’, ‘editable‘ (possible more ie all capabilitiealthough I have not tested)

//////Parameters relating to caching
‘no_found_rows’ => false, //(bool) Default is false. WordPress uses SQL_CALC_FOUND_ROWS in most queries in order timplement pagination. Even when you don’t need pagination at all. By Setting this parameter to true you are telling wordPress not tcount the total rows and reducing load on the DB. Pagination will NOT WORK when this parameter is set to true. For more informatiosee: http://flavio.tordini.org/speed-up-wordpress-get_posts-and-query_posts-functions
‘cache_results’ => true,
‘update_post_term_cache’ => true,
‘update_post_meta_cache’ => true,
//NOTE Caching is a good thing. Setting these to false is generally not advised. For more info on usage see: http://codex.wordpresorg/Class_Reference/WP_Query#Permission_Parameters

//////Search Parameter
s’ => $s,
exact‘ => true
sentence‘ => true

//////Post Field Parameters
//Not sure what these do. For more info see: http://codex.wordpress.org/Class_Reference/WP_Query#Post_Field_Parameters

//////Filters
//For more information on available Filters see: http://codex.wordpress.org/Class_Reference/WP_Query#Filters

);

$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
// Do Stuff
endwhile;
endif;

// Reset Post Data
wp_reset_postdata();

?>

 

For better instruction . here’s the link : https://gist.github.com/luetkemj/2023628

Comments
  1. Carte R4i 3Ds

    It is appropriаte time to mаke some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I ωant tо suggest you ѕome interesting things or advice.
    Maybe you could write next articles referring to this artісle.
    I desire to reаd more things about it!

Leave A Reply

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