Transient pagination not working properly

Short answer: You are making the same query no matter what page you are, but you’re expecting a different result. Long answer: The query should be different for second page, having paged=2, so your query (and transients) with pagination should look like this: $paged_var = get_query_var( ‘paged’ ) ? get_query_var( ‘paged’ ) : 1; if … Read more

Two queries on the same page with pagination

Please use below code hope it’s work for you <div class=”row list-group”> <?php function query_group_by_filter($groupby){ global $wpdb; return $wpdb->postmeta . ‘.meta_value ‘; } global $paged, $wp_query, $wp; $args = wp_parse_args($wp->matched_query); if ( !empty ( $args[‘paged’] ) && 0 == $paged ) { $wp_query->set(‘paged’, $args[‘paged’]); $paged = $args[‘paged’]; } $temp = $wp_query; $wp_query= null; add_filter(‘posts_groupby’, ‘query_group_by_filter’); … Read more

Filter wp_query to search post title in function

If you want to do it via a single WP_Query call, then you can use the posts_clauses filter hook. And the trick is, don’t set the part_number and product_variations_$_part_number meta queries via the meta_query arg, but use the above hook instead, i.e. manually build the SQL clauses. Working Example Note: In your led_search_function() code, the … Read more

Access to Instance Variables from WP_Query

$query = new WP_Query( $args ); if ( $query->have_posts( $query->have_posts()) ) : while( $query->have_posts()) : $query->the_post(); global $post; switch ( $query->current_post ) { case 0 : // first post object is in var $post; echo ‘The first post title is ‘ . $post->post_title; break; case 1 : // because we are insed the loop we … Read more

Search – Ajax – Alter Query Parameters with Pagination

I think this is what you want. base is set via home_url(), format is page/%#%/, search query arg is added via add_args if it exists: $args = array( ‘base’ => home_url( ‘/%_%’ ), ‘format’ => ‘page/%#%/’, ‘current’ => max( 1, get_query_var(‘paged’) ), ‘total’ => $temp->max_num_pages, ); if( isset($_GET[‘s’]) ){ $args[‘add_args’] = array( ‘s’ => $_GET[‘s’] … Read more

Sort in WP_Query(), not filter? Is it possible?

If you want to sort the posts by the meta post_views_count, and still include posts that do not have that meta, you can use meta_query like so: ‘meta_query’ => array( ‘relation’ => ‘OR’, // make sure it’s OR // Include posts that have the meta. array( ‘key’ => ‘post_views_count’, ‘compare’ => ‘EXISTS’, ), // Include … Read more