admin管理员组文章数量:1122846
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'
)
)
);
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'
)
)
);
Share
Improve this question
edited Jul 27, 2015 at 7:29
Pieter Goosen
55.4k23 gold badges115 silver badges209 bronze badges
asked Jul 27, 2015 at 7:11
user1903471user1903471
111 silver badge2 bronze badges
3
- This issue has been handled before, please use the site search, you should get your answer in the returned search results ;-) – Pieter Goosen Commented Jul 27, 2015 at 7:30
- Thanks Pieter, I have search about this issue but not much help. – user1903471 Commented Jul 27, 2015 at 7:47
- Really? ;-) Here is a search with 249 results – Pieter Goosen Commented Jul 27, 2015 at 7:50
1 Answer
Reset to default 0Have 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'
);
本文标签: Create custom query for search
版权声明:本文标题:Create custom query for search? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284740a1927312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论