Skip Navigation

[Closed] Users categories for CPT

This support ticket is created 2 years, 10 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 – 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 11 replies, has 2 voices.

Last updated by Luo Yang 2 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2096127

I have CPT for fishing flies. I already have a taxonomy for that CPT that defines types of flies. Users of the site will be able to login browse the flies and 'label' or categorize them into some basic groups:

1 Flies I want to make
2. Flies I want to buy
3. My favorite flies

So for each user these categories/taxonomy/classification would be different. Another way to think about it would be the user can list all the flies they want to buy or make separately. They are essentially placing flies into thier own categories.

I am unclear how this can be accomplished in Toolset or in WP in general. I know I cant use a taxonomy since that does not vary by user and I don't think custom fields will work since they are applied to the flies CPT.

Do I have to create some kind of psuedo CPT for each user? Seems complex (https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/)

Help appreciated

#2096485

Hello,

In your case, it needs another post type, for example, you can try these:
1) Setup two post types:
- fishing flies
- my flies

2) Setup a taxonomy "label", register to "my flies" post type, with terms:
1 Flies I want to make
2. Flies I want to buy
3. My favorite flies

3) Setup one-to-many relationship between above two post types "fishing flies" and "my flies"

4) Create a post form for creating "my flies",

5) In the single "fishing flies" post, display a form link of step 4)
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/

6) Create a page "My flies", in this page display a nested view:
a) Parent taxonomy view, query all terms of "label"
in view's loop, display below child post view

b) Child post view:
- Query "my flies" posts
- Filter by:
b1) Post author is same as current logged-in user
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
b2) Post type relationship between "fishing flies" and "my flies"
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items
b3) Value set by parent Taxonomy View
https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/
In view's loop, display the parent "fishing flies" post information
https://toolset.com/course-lesson/displaying-related-posts/#displaying-one-related-item-parent

Since Blocks editor does not support taxonomy view, you can setup above views with classic editor:
Dashboard-> Toolset-> Settings-> General, in section "Editing experience", enable option "Show both the legacy and Blocks interface and let me choose which to use for each item I build"
Dashboard-> Toolset-> Views, here you can setup the taxonomy view.

#2097273

Thanks Luo I thought I would have to create this additianal CPT. I have created the CPT and the form and placed it on the single "fishing fly" page (right hand tab eg.hidden link). i have not created the views yet but already there are problems.

First, as you can see i have access the taxonomy for the Myflies but i dont really want to have to have the user click SUBMIT. Just set the taxonomy.
Second, if they do click submit it does create the post with a link to the parent (fly) so that works, but the checkboxes for the taxonomy are refreshed and you dont get to see what you just checked.
Plus, every time you click submit you create a new post in reality I thought it should just keep one and display and refresh it? How do i get the form to refresh with the taxonomy that was previously defined?
thanks

#2097495

Q1) the submit button is required in Toolset post forms, there isn't such kind of built-in feature to create a post without submit button.

Q2) It is creating post form, it won't set the field values by default, as I mentioned above, you can display the child form link by following our document:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

Q3) You can use Toolset Forms API hook cred_success_redirect to redirect him back to the parent "fishing flies" post.
It works like these:
In the single "fishing flies" post, User click the child form link, redirect him to another page, in this page display the child post form, he can create a new child "my flies" post, then redirect him back to parent "fishing flies" post

#2097853

Q1. I can maybe live with having to hit submit
Q2. I can get it to display the child link form but since it does not read the current related my flies post, if the submit button is hit it just creates another"my flies" post so ultimately you can end up with multiple conflicting posts that have can have their taxonomy set different ways. I need the user when visiting that fishing flies post to see they have already classified the fly as one of the three options or all of them. New questions then...

Q4. Can i first display on "Fishing flies post what the current related my flies post has the taxonomy set to?
Q5. How do I ensure only one classification is created for each fly for each user?

thanks

#2098017

Or is there an alternative method I can use that would still allow users to classify flies for themselves?

#2098649

There are lots of questions in this thread, I am trying to answer them one by one:
In the single "fishing flies" post, you can display a post view:
- Query "my flies" posts

- Filter by:
a) post type relationship between "fishing flies" and "my flies"
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items
b) Post author is same as current logged in user
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/

- In view's loop, if there is any result found, display "my flies" post information + parent the editing "my flies" post form link:
https://toolset.com/course-lesson/front-end-forms-for-editing-content/
If there isn't any result found, display the creating "my flies" post form link

So your user will be able to only one child "my flies" post by default, you can still use filter hook "cred_form_validate" to do the validation in server side.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#2103221

Thanks Luo.

I have not gotten to the validate piece yet as I am still struggling with the form and post creation. From the "fishing fly" page (eg. hidden link). i can access the form (i have it in a modular block) and it will create a post. but it wont be associated with the "fishing fly" (current post) at all. even though the form is on that page. They only way I can get it to work is select the "fishing fly" relationship from within the form. Then it does create the post with the correct taxonomy etc etc. How can i get the form to simply use the current post without having to reselect it from a list?

#2103501

You can follow the document to setup the child form link:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/

section "Creating Forms with a Parent Post Preselected"

#2104157

Thanks Luo. Does that mean I have to have a separate page for the form? Also I cant select any page in that dialog. None of my pages appear as options in the" Page that contains the form" field. The form isnt actually on any page?

#2104187

Hey. Think i fixed it by setting the default value for that field in the form set up. Now all I need to do is hide or lock that to prevent the user from accidentally linking to a different Fly.

I should probably start another ticket but if I use the cred_form_validate should I be looking to validate the post for my flies exists or that the taxonomy exists? Any other help with the code for that would be appreciated.

#2104477

Q1) You can use CSS codes to hide the relationship field, if you need assistance for it, please provide a test site with the same problem, I can setup a demo for you.

Q2) the step cred_form_validate is not required for this case, since user can only see the child form link when there isn't any his own child "my flies" post found, see my answer above:
https://toolset.com/forums/topic/users-categories-for-cpt/#post-2098649

If you still need assistance for it, I will split another new ticket for it

The topic ‘[Closed] Users categories for CPT’ is closed to new replies.