[Resolved] I need to filter output in the archive view according to user field.
This support ticket is created 6 years, 7 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.
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.
I am trying to build on local server a site.
I have WP users who have projects. Each project has one user assigned. Each user can have several projects.
I want to output project details for them but only specific projects assigned to each user.
I am trying to do something similar to this https://toolset.com/forums/topic/many-to-many-relationship-with-post-type-and-userauthor-alternative-method/
I have created custom post type Projects
I have created custom user field Project # (could be up to 5 separate fields of type Number).
What I need is to build archive template which could loop through projects filtered according to mentioned in custom user field Project #.
When I am creating archive and try to add filter - there is no option to choose fron custom user field
Dear Shane,
Thanks for the quick reply.
I'm not sure I got what you say.
I am trying to make it while editing cell in the Layouts while creating Archives output. Is this the correct "add filter" button I see on the screenshot that you mean?
Yes this is the correct button but since you are using Layouts it will be best to create a visual editor cell and add the view shortcode to the editor directly, because you are not able to use shortcode parameters if you are using a view cell directly.
Dear Shane I can't understand how to create view shortcode which will filter posts according to custom user field. I tried to create it in view - still no possibility to filter by custom user field. Could you please point me to some guide or tutorial?
I have made a online setup so I can share access for you to show what I am trying to do.
I have custom post type Projects. It has such fields as Title, budget, deadline and "project number" (!). At the same time each wordpress user has custom field "Project ran by user" which contains number (number of the project). Now in the views I am trying to add filter based on custom field "Project number". And I need to pick correct number from custom user field "Projects ran by user" (slug - projects-ran-by-user). Should I choose "shortcode parameter" and insert field slug? Please see the screenshot
Dear Shane,
That's magic and I want to understand how it works!
Thanks for what you have done - you are great!
Just one final question:
1) What should I change in this set up if I need to assign several projects for a user?
I'm happy I was able to assist, all I did was to change the name of the shortcode parameter so it didnt have the hyphens which is why it was working.
Then all I did was to pass the user meta shortcode into that view parameter 🙂
So i'm assuming that the user will have a fixed number assigned to it correct? And since you already have the field on the post all you need to do is use that same number throughout each post.
Dear Shane,
and what if some user has 1 project and another has, let's assume, 5 projects? In my first post there is a link where Christian suggests checkboxes to assign several projects to user but how should I filter them later?
Creating a view will allow you to do this as we discussed.
So if that user only has 1 then the view will only show 1 post and if another user is viewing that same view it will show 5 posts for them because their information is being passed to the view to filter the posts.