Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check only post title and specific post meta data. Not check in Post content or any other field.

I have tried this query

$args = array(
    's' = $keyword,
    'numberposts' = -1,
    'post_type' = 'store',
    'meta_query' = array(
        'relation' = 'OR',
        array(
            'key' = 'postal_code',
            'value' = $keyword,
            'compare' = 'LIKE'
        )
    )
);

Topic meta-query custom-field query Wordpress search

Category Web


Have you check your result-set, what result you are getting in $query obj. another thing, there is no need to use 'relation' => 'OR', in meta query array, have a try with this as well. And instead of 'numberposts' use 'posts_per_page' this will help. :) or you can remove the meta_query and make your $arg something like

$args = array( 's' => $keyword, 'post_type'=> 'store', 'posts_per_page' => -1, 'meta_key' => 'postal_code', 'meta_value' => $keyword, 'meta_compare' => 'LIKE' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.