- This topic has 2 replies, 2 voices, and was last updated 9 years, 8 months ago by .
These forums are now closed and remain for historical purposes.
None of the content applies to the new version 3. For support, get in touch via our contact form.
Forums › Forums › Search & Filter Pro › Filtering by meta
Hi,
I’d like to know if there is a way where I can use a filter to change what shows up in the results.php.
I have a list of resources. Some resources are in English and others are in Gaelic. I have set an option on the user profiles to select one of the languages for the preferred content to be listed. On each of the content items there is also a language select option.
What I’m wanting to do is use a filter to say if the users has selected english then only show the english content items.
Thank you.
Hey Jordan
You could use something like WPML out of the box which would do this kind of thing – its supported by this plugin.
Alternatively, yes you would be able to use pre_get_posts – but we must use a specific priority (copied and pasted from another thread):
function modify_search_filter_query( $query )
{
global $sf_form_data;
global $wp_query;
if ( $sf_form_data->is_valid_form() && $query->is_main_query() && !is_admin())
{
//we can add our modifications here:
$authorID = 1;
$query->set('author', implode(",", $authorID));
//not necessary but we can match the search form ID in case we are using multiple search forms
/*if($sf_form_data->form_id()==797)
{
}*/
}
}
add_action( 'pre_get_posts', 'modify_search_filter_query', 21 );
Thanks
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
We also use cookies to store items in your cart as well as allowing your to login on the site.
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
By continuing to use this site, you also agree to our Privacy Policy.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
More information about our Cookie Policy