Skip Navigation

[Resolved] Filtering a View by custom field in the current post

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

Problem: I have a View that displays Item posts. I would like to display this View on an Auction post. Both Item and Auction have a custom field "donor". I would like to filter the View of Items by the same donor as the current Auction post.

Solution: Use a shortcode attribute in the View's Query Filter configurations, and pass in the field value from the current post using the $current_page operator:

[wpv-view name="Your View Name" donor="[types field='donor' item='$current_page' output='raw'][/types]"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 5 years, 3 months 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ian 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1379283

Ian

I have a site listing auction items that have been donated.
There is a custom field entitled donor

On the auction item single page template I want to display a list of other items donated by the same person.

What I need is to filter the view that "donor" is equal to "donor" of the current post displayed.

I did not see this in the filter options.

#1379507
Screen Shot 2019-11-10 at 4.42.07 PM.png

Hi, the best approach here is to use a shortcode attribute to pass the current post's donor value into the donor field filter. You must configure the View's Query Filter to respond to a shortcode attribute, as shown in the screenshot. If you cannot see the Query Filter panel in your View editor, scroll to the top right corner and click "Screen Options" to activate the panel. Then you will use the Types field shortcode with the $current_page operator to pass the current post's field value into the View. For example:

[wpv-view name="Your View Name" donor="[types field='donor' item='$current_page' output='raw'][/types]"]

It's best to use the raw output attribute to prevent other markup and styles from breaking the filter comparison.

This technique is called passing arguments to Views, and is described in a bit more detail here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

Let me know if you have additional questions about this.

#1380209

Ian

My issue is resolved now. Thank you!