Skip Navigation

[Resolved] Selecting custom post type posts created by a user for a summary report

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

Problem: I would like to allow my site visitors to select a group of posts and generate a report.

Solution: You could handle this with two custom post types - one Report and one Member. Create a many-to-many relationship between these two post types. Then use post relationship Forms to create links between a Report and any Members the User selects.

Relevant Documentation: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

This support ticket is created 5 years, 4 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by DieterR7285 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1308835

Tell us what you are trying to do?
I need to charge clients for reports they create the post content for via forms and can add other related member data-sets to be shown together in the report. The complete data-set will be exported and processed by a third party.
I therefore have created a CRED form for Custom Post Type (CPT) report members that has itself repeatable field group (RFG) posts for those other members.
Yet a new requirement is to be able to select or deselect individual RFG members present in the CPT report as well as add other member data-sets to that final report. Basically being able to create a variety of combinations.

At present I am assuming that I actually need to abandon the present CPT and RFG structure. And create another CPT "sub-member" to create member data-sets and link them to the main CPT report. But I would need them to be author owned by the main report creator and should therefore not be usable by anybody else. And would allow to add general CPT member posts that can be used for any author created CPT main report.
Again these CPT member posts would need to be select-able to create a variety of different "report views" to be exported.

#1308949

Okay so it sounds like you would need to be able to create one post - a report container. Then your Users would need to be able to associate multiple other submember posts with that report container. Some of those submembers would be public, available to all Users for adding in their reports. Other posts would be private, only available to the author of those posts, to add in their reports.

It sounds like the report post type should be in a many-to-many relationship with the submember post type, since you need to allow many submembers to be associated with many reports and vice versa. To establish many-to-many relationships between existing posts, the Toolset way is to use a relationship Form. The big gotcha here is there's no way to associate more than two posts at the same time. In other words, one Form can relate one report and one submember, but there's not a Form that allows you to select multiple submembers to relate to one report in a single submission.

So if you wanted to do exactly this in one form, it's not exactly possible with Toolset out-of-the-box. It would require some custom code using the Forms API and the Post Relationships API. I have information about those resources if you'd like to write custom PHP.

The Toolset workflow would be to create a custom search View that allows your Users to search for submember posts. That View could be filtered so that the public submembers and the User's own submembers are the only results shown. Then in the list of submember results, you could add a link that says something like "Add to report". When the Users click that link, it directs them to a Form where they would see the submember post they selected and have the ability to select a report where the submember should be added. Or if only one report is possible at a time, the User wouldn't have to select the report, it could be preselected. One by one the User could build a report by selecting individual submember posts from the list of results, adding to each report they create.

They would have the ability to view an overview of each report, where you would use a View of related submember posts to display the items that had already been added to the report. You could include a link to remove any submember item, or you could add a link to go back to the custom search View and add more submembers.

More information about relationship Forms here: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

Let me know if you have questions about this.

#1317619

Hello Christian,

Thanks for the detailed reply and going through the linked documentation took a while to get my head around and to implement and test all that.

I followed the Toolset workflow and created the required relationship form and views but could not figure out how to limit the available reports listing and report members to only publicly available ones as well as Author ones!?

Also I am struggling with the Delete relationship function that is implemented in a view and only works for an admin user. But not for the created custom role Report Member. Even so giving nearly as much access rights as the admin user via the Access Control being able to alter and submit edit forms. I followed closely the following troubleshooting guide (https://toolset.com/forums/topic/delete-post-relationship-not-working/) and its recommended documentation links but to no avail.

I have created a new version of the implemented solution which is now in hidden link.

Kind Regards

Dieter

#1318549

I followed the Toolset workflow and created the required relationship form and views but could not figure out how to limit the available reports listing and report members to only publicly available ones as well as Author ones!?
To filter the list of posts, you would use the Query Filter panel in the View editor screen. If you cannot see the Query Filter panel, you can scroll to the top right corner of the View editor and click "Screen Options", where you can enable the Query Filter panel.
How you filter the posts depends on how you want to define a public submember. You could use a custom field, or a taxonomy term, or a specific post type, or a specific post author, or some other indicator that a submember is public. Set up a Query Filter that shows those posts. Then set up a post author Query Filter, where the author is the same as the current logged-in User. Combine the two Query Filters using the "OR" condition.

Also I am struggling with the Delete relationship function that is implemented in a view and only works for an admin user
I'll be glad to take a closer look if you provide login credentials for an admin User as well as a custom role User, and let me know where I should be able to find the "delete relationship" link.

#1319325
Screen Shot 2019-08-19 at 2.33.14 PM.png

Anyway I probably was not that clear in my support request. What I could not figure out is how to limit the listing of reports select able to assign each member to as is possible in the report listing as well as single member "view and edit form".
Check the screenshot here. There is an option in the Relationship Form builder that will limit the results to those authored by the current User. I have made this change for you.

I also have marked in the screenshots where I made it possible for the user to remove a member from a list of report members. That as stated will work only for an Administrator user at the moment!?
I have added the "manage_options" permission in Access Control for the Report Member User, and the delete link seems to be working now. Is this acceptable?

On a different note I would need to add a random number to the member URL to make sure that they stay unique. As over time there will be members with the same name listed.
WordPress will automatically add a number to the post slug if the member names are identical. You can try this out by creating multiple posts or pages with the same name. If you need something more custom, it will require custom code.

And is there a way to make sure that when one creates a new member in a report listing that the form will automatically assign this new member to the report!?
I assume you mean from this page:
hidden link
You click "Create new member" and display the new Member Form. You would like to automatically associate the new Member with the Riedel-Gupta report, correct? If so, this will require custom code using the Forms API and the Post Relationships API, because there is not currently a built-in way to create a post and also add it to a many-to-many relationship automatically.
The general idea is that you would create a hidden generic field in the new Member Form, and insert the ID of the Riedel-Gupta Report as the value of that field. Then you would use the cred_save_data API to get the value of that hidden field when the form is submitted, and use the toolset_connect_posts API to link the new member and the report. If you would like additional assistance with this setup, let's split this into a separate ticket so we can discuss in more detail.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

#1319853

My issue is resolved now. Thank you!

#1320649

As was mentioned in your last answer. Could you please explain in more detail how you would create a hidden field to assign the report ID using the cred_save_data API to make a new member entry directly related to the report it was created under.