$_GET vs get_query_var()

get_query_var() gets variables from the main instance of WP_Query. It’s the equivalent of running global $wp_query; $wp_query->get( ‘posts_per_page’ ); It is not directly related to $_GET in any way. However, WordPress has a list of ‘public’ query variables that will be applied to the main query if they are passed as URL parameters. This is … Read more

Pre_get_post on CPT archive page

pre_get_posts filters run before WordPress has figured out the main query, which is used to pick the template. For this reason you can’t put it inside the template, it has to run before the template is picked, not afterwards. For this reason, it has to go inside your themes function.php or in a plugin

Get access to all terms associated to each post that the wp_query loop displays

If I understood you correctly, you are looking for get_the_terms(), which.. Retrieves the terms of the taxonomy that are attached to the post. You could for example have helper functions like these, // functions.php function my_sports_post_terms( int $post_id ) : array { $taxonomies = [‘basketball’, ‘volleyball’, ‘baseball’]; $terms = []; foreach ($taxonomies as $taxonomy) { … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)