custom query to get posts

Clarification of your question: You want to show Posts of a certain category named “ABC” AND also you want to filter the posts with the tag named “XYZ”. Answer: If this is the scenario, have you tried: WP_Query()? <?php // The Query $args = array(‘post_type’ => ‘post’, ‘category_name’ => ‘ABC’, ‘tag’ => ‘XYZ’, ‘meta_key’ => … Read more

Query Posts by date range with fixed beginning and end

You should probably add the filter, then use a new query, then remove the filter. function filter_where( $where ) { $where .= ” AND post_date >= ‘2012-03-01’ AND post_date <= ‘2014-03-01′”; return $where; } add_filter( ‘posts_where’, ‘filter_where’ ); $query = new WP_Query( array( ‘post_type’ => ‘shop_order’ ) ); while( $query->have_posts() ) : $query->the_post(); the_title(); the_content(); … Read more

Taxonomy Parameters in WP Query to get posts from two different taxonomies

terms parameter of tax query is required. Just pass to it all the terms for taxonomy $args = array( ‘post_type’ => ‘cars’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘brand’, ‘field’ => ‘slug’, ‘terms’ => ‘bmw’ ), array( ‘taxonomy’ => ‘color’, ‘field’ => ‘id’, ‘terms’ => get_terms(‘color’, array(‘fields’=>’ids’) ) ) ) ); Note … Read more

Passing additional variables to a query

If you’re running a custom query like $blog_query, add them right in. If you are wanting to change the main query, use the pre_get_posts action to alter the function. add_action( ‘pre_get_posts’, ‘alter_blog_order’ ); function alter_blog_order( $query ) { if( $query->is_main_query() and $query->is_post_type_archive( ‘post’ ) ) { $query->set( array( ‘orderby’ => ‘post-title’, ‘order’ => ‘ASC’ ) … Read more

Getting grandchildren of a post with a specified custom taxonomy?

I was able to achieve this by, funnily enough, using with get_pages() and WP_Query(). I wanted a reusable function that would return a WP_Query array that I could loop through, so I came up with this: function returnChildGeographies($geoID, $geoType, $grandChildren = false) { $args = array( ‘post_type’ => ‘geographies’, ‘posts_per_page’ => -1, ‘orderby’ => ‘post_title’, … Read more