[Resolved] I need to filter output in the archive view according to user field.

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.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Related documentation: Adding Custom Fields to WordPress

This topic contains 12 replies, has 2 voices, and was last updated by  Mykola Yabchenko 2 days, 3 hours ago. The support staff assigned to this topic is Shane.

Viewing 13 posts - 1 through 13 (of 13 total)
Author
Posts
#569161

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://wp-types.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
Forum moderator

Supporter languages: English (English )

Supporter 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

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
Forum moderator

Supporter languages: English (English )

Supporter 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

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
Forum moderator

Supporter languages: English (English )

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

Hi Mykola,

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

Thanks,
Shane

#571161

Shane
Forum moderator

Supporter languages: English (English )

Supporter 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
Forum moderator

Supporter languages: English (English )

Supporter 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
Forum moderator

Supporter languages: English (English )

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

Viewing 13 posts - 1 through 13 (of 13 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.