I'm trying to this..
function my_search_filter($where) {
$where .= " AND wp_postmeta.meta_key = city AND wp_postmeta.meta_value ='Jakarta'";
return $where;
}
if(is_search()) {
add_filter('posts_where','my_search_filter');
}
but it does not work...
any idea?
Perhaps take a slightly different approach..
add_filter( 'pre_get_posts' , 'add_meta_to_search' );
function add_meta_to_search( $query ) {
if( $query->is_search ) {
$query->set( 'meta_key' , 'city' );
$query->set( 'meta_value' , 'Jakarta' );
}
return $query;
}
When you're checking is_search() you're actually at the point where the query is setup and ready to run, so the posts_where filter is too late in the process of things, so to speak.
wow...
many many thanks t31os_
it's work perfect...
:)
No problem, i'll mark this resolved... ;)
sballinger26
Member
Posted 1 year ago #
hi
i have three tabs(sections) in search page. i want to filter my search as per tabs posts for eg:
1st tab is Post
2nd tab is upcoming events
3nd tab is past events
any help would be appriciated
Thank in advance
Mr. Alexander
Member
Posted 1 year ago #
Hello,
I am trying to do a similar task but using the LIKE term instead of an exact match on the meta_value.
How should I go about that ?
Thank you for your help.