WordPress search exact match

You might want to append the query parameter sentence=1 in your search, it is not well documented, but it should retrieve content inside the post that matches exactly the sentence pattern. Alternatively, for a more powerful search, you might want to give a look at Relevanssi plugin. A lot of people agree that WordPress search … Read more

WP_Query on custom post type not displaying, multiple loops & get_template_part

I think you forgot to check if $the_query have posts. <?php $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’ ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class=”testimonial push_2 grid_10 clearfix”> <blockquote>&ldquo;<?php the_field( ‘testimonial’ ); ?>&rdquo;</blockquote> <cite>&mdash;<?php … Read more

Loop inside the loop

I would use get_posts() for your two ad hoc Loops. (Actually, you only need one ad hoc Loop, if you’re modifying the main Loop so that only 2 posts are retrieved.) e.g. \\ code modify main Loop to return only 2 posts goes here $firstpost = true; if ( have_posts() ) : while ( have_posts() … Read more

How to get post meta value and post in one query?

When you do a query WordPress already gets the post_meta. Even though you are calling get_post_meta() It is not performing another query. It is retrieving the value from the post meta cache. Now if you don’t need the post meta you can set a flag that will eliminate the additional MySql query. To do this … Read more

tax_query in WP_Query problem

Thanks to Rarst for pointing me in the right direction. After a bit of playing around the following query is now producing the effect I’m after: $query_args = array( ‘numberposts’ => $limit, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘post_type’ => ‘match’, ); $query_args[‘meta_query’] = array( ‘key’ => ‘played’, ‘value’ => true, ); if ( isset( … Read more

Query Posts but only return 1 from a custom taxonomy?

I think that using standard WP_Query you should run 6 different loops, but this is overwhelming. But using a custom $wpdb query you can do the trick… function get_unique_posts_tax( $taxonomy = ‘category’, $number = 10, $cpt=”post”) { global $wpdb; return $wpdb->get_results( $wpdb->prepare( “SELECT p.* FROM $wpdb->term_relationships JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id JOIN … Read more

wp_delete_post deletes all posts instead of just expired ones

In case anyone else needs the code, this is how I solved it. @pieter-goosen was right, I did need to query the correct posts, but the real trick was matching the date format from the jquery datepicker when running the post query. Check the date formats below, jquery is ‘yy-mm-dd’, and the php equivalent is … Read more