Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 12 replies, has 2 voices.

Last updated by Mykola Yabchenko 6 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#569161
Знімок екрана 2017-09-12 17.51.45.png

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

#569304

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

Thank you for contacting our support forum.

What you can try doing is adding the filter to the view and set it to filter by the shortcode parameter.

This way you can pass the types shortcode for the user meta into the view so that it can be filtered.

Please let me know if this helps.
Thanks,
Shane

#569819
Знімок екрана 2017-09-14 00.45.06.png

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?

#570006

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

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.

Thanks,
Shane

#570714

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?

#570737
Знімок екрана 2017-09-17 12.42.33.png

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

#571067

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

I've enabled the private fields for her next response.

Thanks,
Shane

#571161

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

Thank you for the credentials.

I managed to take a look at this for you. Try calling your view with this.

[wpv-view name="user-projects" projectnumber="[types usermeta='project-ran-by-user' format='FIELD_VALUE' user_current='true'][/types]"]

Please let me know if it filters correctly.
Thanks,
Shane

#571178

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?

Thanks again!!

#571441

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

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.

Thanks,
Shane

#571444

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?

#571460

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mykola,

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.

Please let me know if this helps.
Thanks,
Shane

#571517

Thank you, Shane. Your help was amazing!
I will try to explore Views further on my own.

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