Skip Navigation

[Résolu] Setting up taxonomy filter based on post title

This support ticket is created Il y a 6 années et 6 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Marqué : ,

This topic contains 10 réponses, has 3 voix.

Last updated by davidS-53 Il y a 6 années et 5 mois.

Assisted by: Luo Yang.

Auteur
Publications
#574723
3.png
2.png
1.png

My scenario is this: I have a number of licensee profile pages. On each licensee page, I want to display posts filtered by a custom taxonomy "event region" (see screenshot 1)

Some of these posts will be national (ie. needing to appear on all licensee pages) and some will be specific to a licensee- i'll need to include all posts with the region set to "national" AND all posts where the taxonomy matches the licensee location.

Problem is, I can't work out how to reflect this in the query filter (see screenshot 2)

My licensee names match my event region names too, to make things clearer (see screenshot 3)

How would I achieve this? Thanks in advance!

#574771

Dear David,

Q1) include all posts with the region set to "national" AND all posts where the taxonomy matches the licensee location.
You can edit each "national" post, enable all terms of taxonomy "event region", then filter the posts by the taxonomy "event region" by follow our document:
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
Value set by URL parameter

Q2) My licensee names match my event region names too ... How would I achieve this?
I assume you are going to filter posts by the post title, you can follow our document to setup the "post title" filter
https://toolset.com/documentation/user-guides/filtering-views-for-a-specific-text-string-search/

#575542
6.png
5.png
4.png

Okay, I can pass the post title successfully as in screenshot 4 & 5.

How do I *also* include "National" posts? I tried as in screenshot 6 but it didn't show anything. I can't see how to add another taxonomy filter- or am I missing something?

#575573

I can see you are using a term "National" in taxonomy "event region", that's the problem, Views can not append the specific term "National" to the query when you filter by other term by default, so there is such a built-in feature within Views plugin, you can try one of below two workarounds:
1) same as I mentioned above:
https://toolset.com/forums/topic/setting-up-taxonomy-filter-based-on-post-title/#post-574771
You can edit each "national" post one by one, enable all terms of taxonomy "event region"

2) Use some custom PHP codes, for example:
a) When user submit the search form, use filter hook "wpv_filter_query" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
b) append the term "National" to the wordpress query
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

#575910

1) This isn't a practical solution.

2a) There is no search form...

2b) Sounds like what I need to do. What exactly would this query modification look like- and how would I limit it to just modify the "View Events on Licensee Page" view's query? I'm assuming I should be using wpv_filter_query, but the documentation for it hasn't helped me much.

Cheers!

#576147

Noman
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi David,

Thank you for your reply. Luo is unavailable at moment, since this is an ongoing ticket, Luo will check your request and get back to you soon with more details. Just like to keep you updated.

Thank you for your cooperation and patience.

#576312

For option 2), It is a custom PHP codes problem, if you need more assistance for it, please provide a test site with the same problem, and fill below private detail box with login details and ftp access, also point out the problem page URL and view URL, and where I can edit your PHP codes, I need a live website to test and debug. thanks

#578046

Thanks for the details, I am checking in your website, will feedback if there is anything found

#578055

The SFTP access you provided is not valid, I can not see the website folder: application/public/
Please check it, also point out the problem page URL and view URL, and where I can edit your PHP codes, I need a live website to test and debug. thanks

#578407

Thanks for the details, I have added below codes into your theme/functions.php:

add_filter( 'wpv_filter_query', 'append_national_term_func', 10, 3 );
function append_national_term_func( $query_args, $view_settings, $view_id ) {
	
    if ( $view_id == 4759 ) {
        if(isset($query_args['tax_query'][0]['terms'])){
			$query_args['tax_query'][0]['terms'][] = 100; // national term ID
		}
    }
    return $query_args;
}

Please test again, check if it is what you want. thanks

#578900

Great, works perfectly! Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.