WP_Query: Why is sticky post not first item in loop?

If you look ate the source code where stickies are included, we find the following condition before WP_Query carries on to include sticky posts if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q[‘ignore_sticky_posts’] ) { The big game player is the is_home condition. Conditionals inside WP_Query is set according to the … Read more

Register custom query args parameter for WP_Query()

After further research I figured out a solution. Given the following WP_Query: <?php new WP_Query( array( ‘s’ => ‘some keyword’, //keyword criterion ‘category’ => ‘some category’, //taxonomy criterion ‘_spec’ => ‘some value’, //custom criterion to be handled by the plugin ) ); ?> You can handle custom parameters using pre_get_posts in combination with posts_where: <?php … Read more

How to do a wp_query using “BETWEEN” with two meta_values?

This should work for you: $tEA = array( ‘post_type’ => ‘event’, // you dont need meta_key as you use meta_query //’meta_key’ => $metaKey, ‘orderby’ => ‘meta_value’, ‘order’ => $order, ‘posts_per_page’ => $postPerPage, ‘meta_query’ => array( array( ‘key’ => $metaKey, // value should be array of (lower, higher) with BETWEEN ‘value’ => array(‘START_DATE’, ‘END_DATE’), ‘compare’ => … Read more

WP query taxonomy input differs to output?

A curious journey of a “cat“ Let’s assume we have the following category hierarchy: where the relevant rows from the wp_term_taxonomy table are: We want to query all posts in the animals category where the id is 65: $query = new WP_Query( array( ‘cat’ => 65 ) ); and try to understand why the resulting … Read more

Delete all posts from WordPress except latest X posts

The offset parameter is ignored with posts_per_page set to -1 in WP_Query. If you look at the source code in the WP_Query class, posts_per_page=-1 sets nopaging to true. if ( !isset($q[‘nopaging’]) ) { if ( $q[‘posts_per_page’] == -1 ) { $q[‘nopaging’] = true; } else { $q[‘nopaging’] = false; } } This in turn will … Read more

When tax_query used, results disappear (0 =1 produced)

tax_query takes an array of arrays. You have an array of arrays of arrays. var_dump($tax_queries); and will get this: array(1) { [0]=> array(1) { [0]=> array(3) { [“taxonomy”]=> string(15) “difficulty_mode” [“terms”]=> NULL [“field”]=> string(4) “slug” } } } Try it without the square brackets. That is turn this: $tax_queries[] = array( array ( ‘taxonomy’ => … Read more

tech