Skip Navigation

[Resolved] Can I show a list of posts based on user category?

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

Problem:

I want to display custom post type (CPT) listings based on categories selected by a user during account registration. For example, if User 1 selects categories A, C, and E, they should only see posts categorized under A, C, and E. User 2 should see posts in categories B and D based on their selection.

Solution:

A possible workaround is adding checkboxes to the user profile during sign-up to store category selections. Then, use a conditional statement on the listing page to display posts based on the user’s selected categories.

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.

This topic contains 4 replies, has 2 voices.

Last updated by Christopher Amirian 7 months, 1 week ago.

Assisted by: Christopher Amirian.

Author
Posts
#2763363

Tell us what you are trying to do?
When a user creates a profile on the site they need to selects some categories.
Example:
User 1 selects category A, C, E on account registration
User 2 selects category B, D on account registration

When user 1 goes to a CPT listing, they should only see posts with category A, C, E
When user 2 goes to the same CPT listing, they should only see posts with category B, D

Is there any documentation that you are following?
I haven't been able to find documentation that resolves this issue.

Is there a similar example that we can see?
I don't have an example

What is the link to your site?
Site is in development.

#2763483

Christopher Amirian
Supporter

Languages: English (English )

Hi,

There is no such feature available in Toolset.

You can use the Toolset access to set a post group to limit access to posts but it should be added by the admin of the website in the WordPress Dashboard and not by the user itself ins9ide a registration form:

https://toolset.com/course-lesson/setting-access-control/

Implementing such feature is outside of our support scope and you can consider hiring a developer for that:

https://toolset.com/contractors/

Thanks.

#2763538

What about if I have User 1 and the user has a "company" CPT (Company 1)
The company has the following categories assigned to it: A, C, E

When the user views a list of all posts, the loop query get's the user's company categories and only shows the posts that share the same categories as the user's company?

So, based on the user, the company category get's passed to the query.

Is that possible?

#2765271

?

#2765279

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Your first sentence can be done. That is creating a post type and assigning a user to the post type entry by setting it as the author of that post type.

You can learn more about that here:

https://toolset.com/lesson-placement/lesson-placements-1622969-1929573/

The second part will be somehow set the custom post type entry for the user (company 1) to get categories that the user wants.

That is not what Toolset can do and it needs custom development. You might need to add generic fields for the form and intercept the form with cred_save hook and get which categories the customer selected. Then you will be able to assign those categories to the entry in question via code.

But is is way outside of our support scope. You can learn more about cred_save here:

https://toolset.com/documentation/programmer-reference/cred-api/

Thanks.

#2769343

I think we were over thinking things.

I resolved this issue by adding a set of checkboxes to the user profile. When they sign-up they check their relevant boxes.

Then I have a conditional statement on the listing page that says:
If current user has checkbox A, then show items categorised as A.