$args = array(
'category__and' => array(1,3), // finding categories 1 & 3
'posts_per_page' => 10,
//'posts_per_page' => -1 , // fetch all posts from db
'year' => 2015,
'monthnum' => 05,
'orderby' => 'title',
'post_type' => 'post',
'category_name' => 'my-category-slug', // finding only current slug category posts
'order' => 'DESC'
);
//Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries. For example, "show me productss where color=orange OR color=red&size=small" translates to the following:
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'orange',
'compare' => '=',
),
array(
'relation' => 'AND',
array(
'key' => 'color',
'value' => 'red',
'compare' => '=',
),
array(
'key' => 'size',
'value' => 'small',
'compare' => '=',
),
),
),
);
$query = new WP_Query( $args );
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'age',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'age',
'value' => array( 3, 4 ),
'compare' => 'IN',
),
),
);
$query = new WP_Query( $args );
//Return posts between 9AM to 5PM on weekdays
$args = array(
'date_query' => array(
array(
'hour' => 9,
'compare' => '>=',
),
array(
'hour' => 17,
'compare' => '<=',
),
array(
'dayofweek' => array( 2, 6 ),
'compare' => 'BETWEEN',
),
),
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
$paged = ( isset( $_GET['pg'] ) && intval( $_GET['pg'] ) > 0 )? intval( $_GET['pg'] ) : 1;
$query_args = array(
'post_type' => 'post',
'paged' => $paged,
'posts_per_page' => 1
);
query_posts( $query_args );
'category__and' => array(1,3), // finding categories 1 & 3
'posts_per_page' => 10,
//'posts_per_page' => -1 , // fetch all posts from db
'year' => 2015,
'monthnum' => 05,
'orderby' => 'title',
'post_type' => 'post',
'category_name' => 'my-category-slug', // finding only current slug category posts
'order' => 'DESC'
);
//Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries. For example, "show me productss where color=orange OR color=red&size=small" translates to the following:
$args = array(
'post_type' => 'product',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'orange',
'compare' => '=',
),
array(
'relation' => 'AND',
array(
'key' => 'color',
'value' => 'red',
'compare' => '=',
),
array(
'key' => 'size',
'value' => 'small',
'compare' => '=',
),
),
),
);
$query = new WP_Query( $args );
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'age',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'age',
'value' => array( 3, 4 ),
'compare' => 'IN',
),
),
);
$query = new WP_Query( $args );
//Return posts between 9AM to 5PM on weekdays
$args = array(
'date_query' => array(
array(
'hour' => 9,
'compare' => '>=',
),
array(
'hour' => 17,
'compare' => '<=',
),
array(
'dayofweek' => array( 2, 6 ),
'compare' => 'BETWEEN',
),
),
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
$paged = ( isset( $_GET['pg'] ) && intval( $_GET['pg'] ) > 0 )? intval( $_GET['pg'] ) : 1;
$query_args = array(
'post_type' => 'post',
'paged' => $paged,
'posts_per_page' => 1
);
query_posts( $query_args );
No comments:
Post a Comment
Please mention your comments.......