Skip Navigation

[Resolved] Cred field parent

This support ticket is created 2 years, 11 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
- 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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Waqar 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2280887

I have a post type called PROJECTS. Each post in this post type is a different client. The client fills out a cred form on their own page, like hidden link, to get us the data for their project. One of the fields they fill out is the name of the pages they want on their website.

Initially I enter in their main top level pages, like ABOUT, MINISTRIES, MISSIONS and then they add subpages to those. The problem is that when they go to choose a top level page in the cred form, all the top level pages from all clients show up in the dropdown list. hidden link

The cred form is using this for this field:
[cred_field field='@inner-pages.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']

How do I fix this so it only shows the top level pages to choose from that are added for that specific project?

#2281437

Hi,

Thank you for contacting us and I'd be happy to assist.

To restrict the dropdown results only to the items added by the current user as post author, you can include the author='$current' attribute:
( ref: https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field )


[cred_field field='@inner-pages.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true' author='$current']

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2281949

Thanks for the reply. I don't think that works because there is no "current author", since the form is public. Can it pull from the id of the current project post instead? So if the url is test.cm/project/company-name-1 then it will only pull from the data entered into that project post, company-name-1.

#2283461

In that case, it will need some workaround, as there is no built-in method available for this.

Can you please share temporary admin login details, along with the link to the form page? I'll be in a better position to guide you with the next steps, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

#2292481

Thank you for sharing these details.

After reviewing the setup, here is the workaround that you'll need:

1. The default 'Top Level Pages' field will show all the 'Site Pages' posts from the repeatable group. Below this field, you can add a 'select' type generic field, that will get the options programmatically from a custom shortcode.

This shortcode will get the current project post's ID and will get all its related 'Site Pages' posts using the "toolset_get_related_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

The post titles and IDs of these posts will need to be output by the custom shortcode in this JSON format:


{"value": "Post 1 ID", "label": "Post 1 Title"}, {"value": "Post 2 ID", "label": "Post 2 Title"}, {"value": "Post 3 ID", "label": "Post 3 Title"}...

Note: An example of a custom shortcode that generates the generic field options can be found in this reply.
https://toolset.com/forums/topic/split-publishing-related-many-to-many-posts/#post-1215323

2. After the generic select field is correctly showing the related 'Site Pages' posts as options, you can include some custom JS code to detect changes in this generic select field and automatically selects the same option in the default 'Top Level Pages' field.

As a result, when the form will be submitted, the post selected in the generic field and the 'Top Level Pages' field will be set as the parent post.

You can also include some custom CSS code in the form to hide the default 'Top Level Pages' field so that the visitors can't change it directly.

I hope this helps and please let me know if you need any further assistance around this.