Limit search results to exact match

I have a problem showing results in WordPress with WP_Query. Problem is simple but as far I’m not programer I wound it difficult.

So, I have custom field with values like 1-1-1-1 and 2-1-1-1-1 for example. And when I search for example 1-1-1-1 it gives me also second result and thats what I dont want to. I only want exact match to show in my search results. Can anybody help me out?

Read More

code:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        global $wp_query;

        $query = new WP_Query( 'meta_key=wpcf-resitevtags' );
        $query = $wp_query->query;
        if (!is_array($query)) parse_str($query, $query); 
        $custom_query = new WP_Query(array_merge($query, array('posts_per_page' => $gantry->get('search-count'), 'meta_key' => 'wpcf-resitevtags', 'posts_per_page' => 22,  'paged' => $paged)));
         ?>

        <?php if($custom_query->have_posts()) : ?>

        <?php if($gantry->get('search-page-title')) : 

        ?>
        <?php endif; ?>

        <?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>

        <?php

        //$title    = strip_tags(get_the_title());
        $content    = strip_tags(strip_shortcodes(get_the_content(false)));
        $excerpt    = strip_tags(strip_shortcodes(get_the_excerpt()));
        $keys       = explode(" ",$s);
        //$title    = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="search-excerpt"></span>', $title);
        //$content  = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="search-excerpt"></span>', $content);
        //$excerpt  = preg_replace('/('.implode('|', $keys) .')/iu', '<span class="search-excerpt"></span>', $excerpt);

        ?>

Related posts

Leave a Reply

1 comment

  1. I guess a meta_query should help you.

    $query = new WP_Query( array(array(
                                        'key' => 'wpcf-resitevtags',
                                        'value' => '1-1-1-1' 
                                        'compare' => '='
                                ))
                        );