Paginate get related post by author function

As I already stated in a comment to your answer, you should never make use of query_posts Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of … Read more

How to get posts without author?

That won’t be as easy as you’d like to… get_posts uses WP_Query to get posts and if you take a look at WP_Query code, ten you’ll see, that 0 is used as empty in there (https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/class-wp-query.php#L2052): if ( ! empty( $q[‘author’] ) && $q[‘author’] != ‘0’ ) { It means, that you can’t pass ‘author’ … Read more

Problem with get_posts, tax_query and counting the number of posts

Try this again removing operator and relation arguments as follows: here is a useful link http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/ $products = get_posts(array( ‘post_type’ => ‘products’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘collection’, ‘field’ => ‘slug’, ‘terms’ => array($current_collection) ), array( ‘taxonomy’ => ‘type’, ‘field’ => ‘slug’, ‘terms’ => array($current_type) ), array( ‘taxonomy’ … Read more

get_posts only children from certain parents

You have two options: Call get_posts multiple times: one for the parent pages using post__in => array(2,4), and two for the child pages of each parent with post_parent => 2 and post_parent => 4 and finally merge all the results into a single array. Write directly your SQL query and use $wpdb->get_results. See this article … Read more

Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?

The default arguments for get_posts() function include ‘numberposts’ => 5. So if you’re querying for a search term that returns more than five (5) results the second query will return a maximum value of 5 unless you pass ‘s=computer&numberposts=-1′ as your query string. The WP_Query object doesn’t have a ‘numberposts’ default, although it is affected … Read more

What should I use, get_posts or wp_query for less CPU load?

I doubt using get_posts() vs WP_Query() would make any meaningful/noticeable difference in CPU load. Ultimately, get_posts() is just a wrapper for WP_Query(), anyway: $get_posts = new WP_Query; return $get_posts->query($r); You would be better served by looking at the efficiency of the queries themselves; but to provide specific assistance there, we would need to see each … Read more