Skip Navigation

[Resolved] Displaying Fields of Parent Pages in a CRED Form

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.

Our next available supporter will start replying to tickets in about 5.81 hours from now. Thank you for your understanding.

This topic contains 8 replies, has 3 voices.

Last updated by Joff 7 years, 4 months ago.

Author
Posts
#172179

I have a parent-child relation fpr posts: parent is a "workshop", child is a "application/attendee" for a workshop. I'm using a cred form for the application of a workshop according to this user guide: https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

As far as I see I can only disply tile and URL of the parent page in the form, correct?
But I would like to display more custom fields that I have defined for the parent post, e.g. the date and the price of the workshop. I'd like to display this information both on the form page and in the confirmation email that is sent to the user.
How to achieve that?

#172214

Agnes Bury
Supporter

Languages: English (English )

Timezone: Pacific/Midway (GMT-11:00)

Dear thomasD-2,
you can always reference to all parent fields from a child view/CRED form adding parent id attribute like in the following example:

Parent: Company
Child: Employee

<span>Employee's company name: [types field="company-name" id="$company"][/types]</span>

where company is parent's slug you defined in Types setting when defining your custom post type

#172278

Hello Agnes,
thx for the quick response. However the solution doesn't work on my server. Nothing is displayed when I insert the following code in my CRED form:
<span>[types field="preis" id="$veranstaltung"][/types]</span>
What's wrong with this?
The slug of the parent post type is "veranstaltung", the name of the custom field is "preis".
The CRED form is integrated via shortcode on a separate page, and the page is opened via a child link - the URL of the page looks like this: /wordpress/../newpage/?parent_veranstaltung_id=288.

One the page the parent title is shown via this shortcode:
<h2>Workshop[cred-post-parent get='title']</h2>
But I can not manage to display the parent field "preis"

#172290

Agnes Bury
Supporter

Languages: English (English )

Timezone: Pacific/Midway (GMT-11:00)

Dear thomasD-2,
first thing first, make sure you use your CRED form in the relevant place.

Is the CRED form displayed on the page you mentioned? Can you see all the input form fields you defined creating your CRED form? If you cannot see none of them this means that you inserted your CRED form not in the right place.

For example if you have an Edit Form for a child post you cann't display the form anywhere. The form must be applied to a specific post. The post which is going to be edited via the form. So the best place to insert Edit Form is a Template Content for single custom post.

You can as well insert the CRED form in other places, like a page but the CRED must be in a way related to a single custom post you which is going to be edited via the form. You can insert the CRED form with a specific post id in this case. See:

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred-link-form

#172622

Hi Agnes,
yes, I can see my form, and it is fully functional. It shows a select dropdown with the available items (veranstaltungen), and the chosen "Veranstaltung" (submitted to the form via URL-parameter "?parent_veranstaltung_id=288") is already pre-selected. The user can fill the form and sumbit the data etc. All this works fine. The only thing is that I can't display any fields from the parent post other than the title and the URL.

There are these two shortcodes I can use for title and URL: [cred-post-parent get='title'] [cred-post-parent get='url'] What I would need is a shortcode also for the other fields. My setup is pretty similar to the book review example explained here: https://toolset.com/documentation/user-guides/cred-forms-for-child-content/. In this document it is recommended that the new-content form is placed on a page.

I've played around with the solution that you suggested, the shortcode [types field="company-name" id="$company"]. This works fine for displaying of _existing_ posts and the respective parent content. But it doesn't work for newly created content. This seems to be kind of a shortcoming in the functionality of CRED, as CRED knows from the URL-parameter about the parent page of the content that is going to be created with the empty form. Maybe you can take that into account for further updates of CRED.

Do you think that there is a solution for my requirement?

#173142

Agnes Bury
Supporter

Languages: English (English )

Timezone: Pacific/Midway (GMT-11:00)

Dear thomasD-2
you are right. The code I showed above will only work when used in an Edit form. This is because the post id is already known.

You can however show the full parent's info when creating a new child post as well, using CRED. I will show you how but first I must prepare some screenshots to explain it step by step. I will keep you posting.

#173191

Agnes Bury
Supporter

Languages: English (English )

Timezone: Pacific/Midway (GMT-11:00)

1-filter-by-parent-id.JPG
2-company-full-info-view.JPG
3-view-in-a-cred-form.JPG
4-view-list-all-parents.JPG
5-cred-add-form.JPG

The idea:
1. You create a View showing full parent info based on a specific id received in URL (see picture 1, this is a simple View having Company post type selected in 'Content Selection' section and all Companies fields in the loop, see picture 2)
2. You insert this View in your CRED form for creating a new child (see picture 3)
3. The add new child CRED form must be called with the parent's id being passed into (see picture 4)

When you click Add Employee button your URL will look like this:
hidden link

look at the end, there is ?parent_company_id=333
so now, the CRED form knows his parent's id and the View used in that form receives the id as a parameter. Now is ready to show full parent info (see picture 5)

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#174793

This solution works perfectly. Thx very much for your detailed and very helpful support.

#320325

A shorter way might be what I have just sorted out.

I was just wanting to pull the parent title into my form. I have the form shortcode within the page.

I slightly modified Louy's code at https://toolset.com/forums/topic/auto-fill-parent-field-in-cred-form/page/2/#post-320324 to suit my needs

//Shortcode to get current page as parent (for CRED form relationships)
add_shortcode('current-parent-title', 'current_parent_id_func');
function current_parent_id_func($atts, $content){
    $queried_object = get_queried_object();
    $title = get_the_title($queried_object);
    return $title;
}

Now the [current-parent-title] shortcode provides the parent title. As get_queried_object returns the current post, this could be modified to extract any post data really.