[Resolved] Setting up taxonomy filter based on post title

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.

Our next available supporter will answer your ticket in about 2.51 hours from now. Thank you for your understanding.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

This topic contains 10 replies, has 3 voices, and was last updated by  davidS-53 4 days, 23 hours ago. The support staff assigned to this topic is Luo Yang.

Viewing 11 posts - 1 through 11 (of 11 total)
Author
Posts
#574723

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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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://wp-types.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://wp-types.com/documentation/user-guides/filtering-views-for-a-specific-text-string-search/

#575542

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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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://wp-types.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://wp-types.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
Forum moderator

Supporter languages: English (English )

Supporter 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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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

#578055

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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.

Viewing 11 posts - 1 through 11 (of 11 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.