The first thing is that, you should have identical slug so that we can match the category term slug with the custom user field value.
So, as you can see with your user custom field group:
- hidden link
I've set the value of your custom field as per the category slug:
- hidden link
For instance, the slug is "gauteng" for category "Gauteng", I have changed the location user field option value as "gauteng" for the option "Gauteng". So we can match the category slug equal to your custom field value. I hope that makes sense.
To you view, I've added the following query filter under the "Query Filter" section:
=> hidden link
Taxonomy filter
Select posts with taxonomy:
Categories slug in one of those set by the View shortcode attribute wpvcategory
eg. [wpv-view name="view-name" wpvcategory="xxxx"]
And configure the no items found message when there is no selection of location or section field in user profile page it will display the following message.:
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]You'll need to select a location and or a sector in order to view these results.[/wpml-string]</strong>
[/wpv-no-items-found]
Then to your page:
- hidden link
I've added the "Fields and Text" block and added the following shortcodes that will display the current user selection for location and section fields:
User location: [types usermeta='location' output='raw' separator=', ' current_user='true'][/types] <br/>
User Sector: [types usermeta='sectors' output='raw' separator=', ' current_user='true'][/types]
<br/>
And then added the View's shortcode as given under:
[wpv-conditional if="( '[types usermeta='location' output='raw' current_user='true'][/types][types usermeta='sectors' output='raw' current_user='true'][/types]' ne '' )"]
[wpv-view name="tender-list-3" wpvcategory="[types usermeta='location' output='raw' separator=',' current_user='true'][/types],[types usermeta='sectors' output='raw' separator=',' current_user='true'][/types]"]
[/wpv-conditional]
[wpv-conditional if="( '[types usermeta='location' output='raw' current_user='true'][/types][types usermeta='sectors' output='raw' current_user='true'][/types]' eq '' )"]
[wpv-view name="tender-list-3" wpvcategory="0"]
[/wpv-conditional]
Where:
- We are checking for location and section field and if (location or section field) is not empty then it should get the value using the [types] shortcode and assign the value to shortcode attribute "wpvcategory":
- if (location or section field) is empty we pass the 0 to shortcode attribute wpvcategory="0"
For now, my user profile do not have any selection so it displays the message "You'll need to select a location and or a sector in order to view these results.":
- hidden link
Can you please check now: hidden link
More info:
- https://toolset.com/course-lesson/filtering-custom-lists-of-posts/#value-set-by-view-shortcode-attribute
- https://toolset.com/course-lesson/filtering-custom-lists-of-posts/#filtering-by-taxonomy
- https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/