Query to return maximum of one post per author

You need to GROUP BY the author ID, which is going to require a filter on posts_groupby. The Codex page for that filter is non-existent but it works like posts_join. Something like… function filter_authors($groupby) { global $wpdb; $groupby = ” {$wpdb->posts}.post_author”; return $groupby; } add_filter(‘posts_groupby’,’filter_authors’); $args = array( ‘showposts’ => 3, ‘author’ => “1,2,3” ); … Read more

Make First post different from rest?

You could check current_post in the loop: if($queryObject->have_posts()) { while($queryObject->have_posts()) { $queryObject->the_post(); if( 0 == $queryObject->current_post ) { // this is the first post } else { // not the first post } } }

Why is my WP_Query not working when tax_query terms are an array?

When you’re doing a tax_query or meta_query in a WP_Query, you always have to use a nested array( array() ); just see the following example for an explanation and pay attention to the relation argument. $packages = new WP_Query( array( ‘post_type’ => ‘vamos-cpt-packages’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘vamos-holiday-types’, ‘field’ => … Read more

WP_Query with meta_value LIKE ‘something%’

For a left-sided match you can get around the automatic adding of ‘%’‘s by WP by using regular expression RLIKE: ‘meta_value’ => ‘^’ . preg_quote( $today ), ‘meta_compare’ => ‘RLIKE’ Similarly for right-sided match: ‘meta_value’ => preg_quote( $today ) . ‘$’, ‘meta_compare’ => ‘RLIKE’

Getting an array out of WPQuery

Your function returns $product->get_id();, instead of that, you should save those values into an array and at the end return that array. function ids(){ $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘product’, ‘meta_key’ => ‘wppl_is_dax’, ‘meta_value’ => ‘1’ ); // query $the_query = new WP_Query( $args ); $allIds = array(); if( $the_query->have_posts() ): while( … Read more

How to limit the posts

It should be: $newsposts = new WP_Query(‘cat=restaurant&posts_per_page=7’); Another way to write it (helps readability with larger queries) would be: $newsposts = new WP_Query(array( ‘cat’ => ‘restaurant’, ‘posts_per_page’ => 7, )); See WP_Query in Codex for description of available parameters. PS would be good practice to add wp_reset_postdata() at the end. You are (correctly) not modifying … Read more