Custom Wp_query loop takes very long

I found a solution to my question. I used the following code: global $wpdb; if($t_query->have_posts()){ while($t_query->have_posts()){ $t_query->the_post(); echo $wpdb->last_query.”\r\n”; } } and it showed there was an action somewhere hooked to the_post hook, sending requests to update some meta every time a post was processed. So, the answer to my question is: I should have … Read more

wp_query loop with compare operator simply not working, why?

As stated in the documentation: (bold formatting was added by me) Note that meta_query expects nested arrays, even if you only have one query. So your meta query should actually look like the following, and note that in a meta_query, we don’t use the meta_ prefix, e.g. we use just key and not meta_key: $query_args[‘meta_query’] … Read more

Get X posts with the same terms as the current post (custom post type and custom taxonomy)

It’s not limiting to 5 posts That’s because the posts_per_page arg should actually be in the same level as the post_type arg and not put inside the tax_query array. I.e. $args = array( ‘post_type’ => ‘oferta’, ‘posts_per_page’ => 5, // add it here ‘tax_query’ => array( array( ‘taxonomy’ => ‘categoria’, ‘posts_per_page’ => 5, // NOT … Read more

How does ‘category__not_in’ differ to cat => ‘-1’?

Looking at the codebase, the only difference appears to be that category__not_in excludes child terms from selection, whereas cat does not. Should category__not_in be used with caution, similar to posts__not_in? Absolutely, but for different reasons. The main issue with excluding posts is that it causes problems for caching – every query with a different excluded … Read more