Forums › Forums › Search & Filter Pro › modify $query
- This topic has 14 replies, 3 voices, and was last updated 6 years ago by Ross.
-
Anonymous(Private) October 17, 2018 at 3:22 pm #191180
I would like the results of a term of this taxonomy to always be displayed when selecting a term from my own taxonomy.
Example:
Taxonomy: Regions
Terms: Austria, Vienna, Salzuburg etc.
Articles with the term “Austria” should always be displayed if one of the other terms is selected.For the taxonomy archive page I have added the following to the “functions.php”:
function my_modify_main_query( $query ) { if ( !is_admin() && $query->is_main_query() ) { $query->set( 'tax_query', array( 'relation' => 'OR', array( 'taxonomy' => 'region', 'field' => 'slug', 'terms' => 'Österreich' ), ) ); } } add_action( 'pre_get_posts', 'my_modify_main_query' );
Unfortunately this does not affect the result of “Search & Filter”. I use the shortcode method for display and in the file “results.php” the element “$query” is actually addressed as well.
Any approach on how to get my behavior realized?
Trevor(Private) October 17, 2018 at 3:36 pm #191183I am not sure this is the way to achieve your aim, although I am not entirely sure what you ware trying to do.
Are you able to send me a live link/URL to your search page so I can take a look?
Can you suggest a search for me to make, and detail what does happen (what posts appear), and what you want to see?
Anonymous(Private) October 18, 2018 at 1:18 pm #191245Yes, when I choose Austria the article refers to the whole country.
If I select a single region, the articles that are tagged for the whole of Austria should also be displayed.Perhaps a more detailed explanation. I have the following articles.
Article A, B, C with tag “Austria”
Article D, E, F with tag “Vienna”
Article G, H, I with tag “Tyrol”Tag Selection “Austria” shows the articles: A, B, C
Tag Selection “Vienna” shows the articles: A, B, C, D, E, F
Tag Selection “Tyrol” shows the articles: A, B, C, G, H, II’ve already customized the output of “$query” (see first post) via the “functions.php and that works for the tag archive page of the regions. Unfortunately it doesn’t affect the results of “search & Filter Pro”.
Anonymous(Private) October 18, 2018 at 6:49 pm #191286Now I thought about the problem again and looked at the documentation. I found the following: “Edit Query Arguments”.
Then I tried the following:
function filter_function_name( $query_args, $sfid ) { if($sfid==163) { $query_args['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'region', 'field' => 'slug', 'terms' => array( 'Österreich' ), ), ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Unfortunately this works exactly the other way round to what I want.
Now only articles with the tag Austria are displayed.Is there any way to modify it to work the way I think it should?
-
AuthorPosts