Tell us what you are trying to do?
I have a view that lists users that are tagged to a post type (exhibitors). We're using the CONTAINS method as recommended in your support and a custom taxonomy.
[wpv-conditional if="( CONTAINS(#(exhibitor-member),'[wpv-user field='ID']') eq '1' )"]
[wpv-post-body view_template="loop-item-in-associated-staff"]
[/wpv-conditional]
This is working (sort of) to list users have their ID as a tag on the post using that exhibitor-member taxonomy. Except it's also outputting other users.
Is there a similar example that we can see?
I've included screenshots of the website and post.
What is the link to your site?
Hello,
You can use WP function has_term() as condition of shortcode [wpv-conditional], for example:
1) Dashboard-> Toolset-> Settings-> Front-end Content, in section "Functions inside conditional evaluations", add the function name: has_term
2) Setup the shortcode like this:
[wpv-conditional if="( has_term('[wpv-user field='ID']', 'exhibitor-member', null) )" debug="true"]
Display something here...
[/wpv-conditional]
More help:
https://developer.wordpress.org/reference/functions/has_term/
I've implemented the change which still isn't working as it should.
When I add the shortcode as stated with the debug I get...
####################
wpv-conditional attributes
####################
Array
(
[if] => ( has_term('2', 'exhibitor-member', null) )
[debug] => true
)
####################
Debug information
####################
--------------------
Original expression: ( has_term('2', 'exhibitor-member', null) )
--------------------
After matching 1 numeric strings into real numbers: ( has_term(2, 'exhibitor-member', null) )
Matched '2' to 2
####################
wpv-conditional attributes
####################
Array
(
[if] => ( has_term('3', 'exhibitor-member', null) )
[debug] => true
)
This seems to indicate that the function is checking. I've added the userID '2' onto the tags so it should return true for number 2 and false for number 3.
When I remove the debug it doesn't display anything and I tried changing the shortcode to
[wpv-conditional if="( has_term('[wpv-user field='ID']', 'exhibitor-member', null) eq '1' )"]
Display something here...
[/wpv-conditional]
Which I figured would adjust it to show only when the user id appears in the tags which still results in nothing.
It works fine in my localhost, and in your debug logs, it works fine too, if you need more assistance for it, please provide a test site with the same problem, also point out the problem page URL, I need to test it in a live website.
Thanks for the details, I have checked the URL you mentioned above, in your case, it does not need [wpv-conditional] shortcode, you can put the filters into the user view directly, I have setup a demo in your website:
1) Edit user view "Associated Staff":
hidden link
in section "Query Filter", add a filter:
Select users with id set by the View shortcode attribute "users" and with role "(any)"
eg. [wpv-view name="view-name" users="1"]
2) Edit the problem post:
hidden link
a) You can get current post's exhibitor-member terms with shortcode:
[wpv-post-taxonomy type="exhibitor-member" format="slug" item="$current_page"]
b) Pass above shortcode to user view like this:
[wpv-view name="associated-staff" users='[wpv-post-taxonomy type="exhibitor-member" format="slug" item="$current_page"]']
Test it in front-end:
hidden link
It works fine, please check if it is what you want.
My issue is resolved now. Thank you!