Skip Navigation

[Resolved] Toolset Loop Filter Loops Using Contains Not Working (Giving Extra Responses)

This thread is resolved. Here is a description of the problem and solution.

Problem:

Pass user IDs as attribute of user view.

Solution:

It does not need [wpv-conditional] shortcode, you can put the filters into the user view directly, see example here:

https://toolset.com/forums/topic/toolset-loop-filter-loops-using-contains-not-working-giving-extra-responses/#post-1826695

Relevant Documentation:

This support ticket is created 4 years ago. 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.

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)

This topic contains 5 replies, has 2 voices.

Last updated by MichaelW8226 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1821521
2020-10-22_14-55-11.png
2020-10-22_14-57-02.png

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?

#1822209

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/

#1825209

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.

#1825477

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.

#1826695

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.

#1827471

My issue is resolved now. Thank you!