Skip Navigation

[Resolved] how to filter view by post-id of related post

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

Problem:

How can I filter the view so that it uses the usermeta field (agency-post-id)?

Solution:

You can get the usermeta field (agency-post-id) value using Types shortcode, for example:

[types usermeta="agency-post-id" user_current="true"][/types]

Then pass above shortcode as Views attribute to get the related agency posts.

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/functions/

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 2 replies, has 2 voices.

Last updated by Amin 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1579367

I have a post type called Agency. I have another post type called Candidate. I've created a relationship where one Agency can have many Candidates.

Each Agency can also have many "managers", so I've stored the Agency post-id into a usermeta field (agency-post-id) of each "manager" user.

I've created a view that lists all Candidates but I want to filter the results based on the agency that the candidate is related to.

How can I filter the view so that it uses the usermeta field (agency-post-id)?

The end result should be that if a user (manager) belonging to a certain agency visits this page, they should see all the Candidates that are related to his agency.

#1579471

Hello,

How do you setup the usermeta field (agency-post-id)? With Toolset Types plugin?
If it is, you can try these:
1) Setup a post view: "view-name"
- Query agency posts
- Filter by:
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-post-id/
- In view's loop, display agency post infomation + related "Candidate" posts:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

2) You can get the usermeta field (agency-post-id) value using Types shortcode, for example:
[types usermeta="agency-post-id" user_current="true"][/types]
https://toolset.com/documentation/customizing-sites-using-php/functions/

Then pass above shortcode as Views attribute to get the related agency posts:
For example: [wpv-view name='view-name' ids='[types usermeta="agency-post-id" user_current="true"][/types]']
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

#1579907

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.