WP_Query offset argument does not work

The offset index for WP_Query generally works with pagination. When you set pagination to a -1 the function assumes you’re getting all posts and there will be no pagination or offset. So to counteract this you would set the posts_per_page to a high number like 999. Reading the Function Reference on WP_Query the pagination section … Read more

WP_Query result in form of Rest API results

I think we can simplify it with: $request = new WP_REST_Request( ‘GET’, ‘/wp/v2/posts’ ); $response = rest_do_request( $request ); $data = rest_get_server()->response_to_data( $response, true ); by using rest_do_request().

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

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