wp_query not searching with apostrophe

Try using sanitize_text_field instead of esc_html wp> $search_query = “Dalton’s Law <br/>”; string(18) “Dalton’s Law <br/>” wp> $query = apply_filters( ‘get_search_query’, $search_query ); string(18) “Dalton’s Law <br/>” wp> $esc_html = esc_html( $query ); string(29) “Dalton&#039;s Law &lt;br/&gt;” wp> $sanitized = sanitize_text_field( $query ); string(12) “Dalton’s Law” esc_html should be used to escape output before it … Read more

Offset Page Loops and Pagination

I messed around with the code some more, and my particular issue actually ended up relating to the original if statement parameters. Changing the condition to check the home page for queries to if ( $query->is_home() && ! $query->is_main_query() ) { return; } and else { //This is the first page. Just use the offset… … Read more

Query different number of posts with different formats in one go

This isn’t possible in one query. You can’t set posts per page for individual taxonomy queries. You can either query 12 status or aside posts together: array( ‘posts_per_page’ => 12, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-status’, ‘post-format-aside’ ), ), ), ) Or perform separate queries with get_posts() … Read more

Search Posts with Custom Fields as query

There are few ways to solve this problem… 1. Don’t bother and use Relevansi (or some other similar plugin) You can often hear that using many plugins is a bad thing. It’s not entirely true. It’s bad only if these plugins have big impact on use of resources. In this case, Relevansi won’t cause such … Read more

WP_Query ajax loader detect end of posts

Page template: <div class=”entry-content”> <?php $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => ‘2’, ‘paged’ => 1, ); $my_posts = new WP_Query($args); if ($my_posts->have_posts()) : ?> <div class=”my-posts”> <?php while ($my_posts->have_posts()) : $my_posts->the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <?php endwhile; ?> </div> <?php endif; ?> <div class=”loadmore”>Load More…</div> </div> Ajax … Read more

WP_Query meta_query >= date

What is missing? One tiny detail… And it’s easy to overlook… the_field(‘datum_event’); Prints the field using the format you’ve defined in field settings. But… It has nothing to do with how the value of that field is stored in DB. ACF uses YYYYMMDD format when storing date values in DB. And WP_Query doesn’t use field … Read more