Query for posts in 2 taxonomies

According to the Codex, here’s how you would query posts from several taxonomies: ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘videoscategory’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug ), array( ‘taxonomy’ => ‘yourothertaxonomy’, ‘field’ => ‘slug’, ‘terms’ => $other_custom_term->slug ) )

creating wp query with posts with specific category

Use either: $the_query = new WP_Query(‘posts_per_page=2&category_name=events’); or $the_query = new WP_Query(array( ‘posts_per_page’ => 2, ‘category_name’ => ‘events’, // this is the category SLUG )); // EDIT Please note that category_name actually is the category slug (which is for one-word names originally the same). It is not the actual name (maybe having spaces, special characters etc. … Read more

WP_query : meta_key with custom rule for specific value

A meta_query is an array of arrays. Look at the examples in the the Codex. $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); What you have is … Read more

meta_query on a date range using an array of values

I needed to get post with type event and the custom field “date” later than today, this sample of code worked perfectly for me, I hope it helps to someone in a similar situation. $today = date(“Y-m-d”); $today1 = date(“Ymd”, strtotime(“$today”)); $custom_meta = array( array( ‘key’ => ‘data_de_inicio’, ‘value’=>$today1, ‘compare’=>’>’, ‘type’=>’date’, ), ); $query = … Read more

How can i get the last post from wp multisite?

The orderby-parameter should be post_date instead of date. your code would look something like this: $blogs = get_last_updated(‘ ‘, 0, 1); foreach ($blogs AS $blog) { switch_to_blog($blog[“blog_id”]); $args = array( ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘numberposts’ => 1, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true ); $lastposts = get_posts( $args ); foreach($lastposts … Read more

WP_Query search for whole words

You’re gonna need regular expressions to accomplish that. First of all, you need to change ‘LIKE’ to ‘RLIKE’ (or ‘REGEXP’). Second, replace $keyword in ‘value’ with a regex that involves word boundaries. Like so: $queryArgs = array( ‘post_type’ => ‘faculty’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘proposed_keywords’, // name … Read more