Forums › Forums › Search & Filter Pro › Use meta query with Search & Filter Pro
- This topic has 2 replies, 2 voices, and was last updated 9 years, 11 months ago by
Anonymous.
-
Anonymous(Private) May 18, 2015 at 8:59 pm #17796
Hi, I use Search & Filter Pro plugin. It works very very good. I have some custom post types and I have setup some forms that allows the user to filter results when he is view an archive page. My Settings are as follows.
Display results: As an archive page
Use a custom template for results? Yes
Enter the filename of the custom template: archive-expenses.php (my custom post type is called expenses)
Load results using Ajax? YesThe problem is that I want to use an extra meta_query when filtering that it comes from the current user meta. To be specific I have a user meta (user_group) and I use the code below with the pre_get_posts hook but I cannot make it worh with the Search & Filter Pro plugin:
$user_group = get_the_author_meta(‘user_group’, get_current_user_id());
if($user_group != ‘administrator’){
$meta_query = array(
array(
‘key’ => ‘visits_user_group’,
‘value’ => $user_group,
‘compare’ => ‘=’
)
);
$query->set( ‘meta_query’, $meta_query );
}Any ideas? Thanks in advance!
Ross Moderator(Private) May 18, 2015 at 9:24 pm #17804Hey Alexander
Please see the following post as an example of hooking into Search & Filter queries:
This will be changing in S&F 2.0, as there are some new functions and considerations, however these will be well documented once they are ready.
Thanks
Anonymous(Private) May 20, 2015 at 8:04 pm #17957Hi, thanks for your quick reply !!!
Ok I get make it work. In my code I make use pre_get_posts to filter the results at a given custom post type archive. The reason that it was not working was that when geting the query from filtering it does not work this code “$query->is_post_type_archive(‘expenses’)”.
So I replaced this:
if( $query->is_main_query() && !is_admin() && $query->is_post_type_archive(‘expenses’) ) { }
with this:if( $query->is_main_query() && !is_admin() && ($query->is_post_type_archive(‘expenses’) || $sf_form_data->form_id()==1864) ) { }
-
AuthorPosts