Skip Navigation

[Résolu] how to filter view by post-id of related post

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 4 années. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 réponses, has 2 voix.

Last updated by Amin Il y a 4 années.

Assisted by: Luo Yang.

Auteur
Publications
#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.