Skip Navigation

[Gelöst] Child post requires me to enter field data of parent

This support ticket is created vor 8 Jahre, 3 Monate. 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.

This topic contains 6 Antworten, has 2 Stimmen.

Last updated by joshB-6 vor 8 Jahre, 3 Monate.

Assisted by: Ross Fisher.

Author
Artikel
#364943

I am busy working on an auction companies catalogue for their previous auctions.
I have 4 custom post types:
1) Sale
2) Session (parent: Sale)
3) Lot (Parent: Sale, Session)
4) Category ( I might change this to a custom taxonomy for Lot)

Step one:
Add new sale

Custom fields for sale include:
Sale Name
Sale Number
Location
Start Date
End Date

Step two:
Create new lot
Custom fields pictured below:
hidden link

beneath that field it asks me to enter the sale information:
hidden link

How do i make it that this data is populated by selecting the parent from a drop down box like it is in the real estate site demo:
hidden link

I am happy to supply admin login if you need to look first hand.

Regards.
Josh

#364978

Update:

I was able to finally figure out that the reason I wasn't able to save Auction Lots was because the parent categories' fields were marked as required.

However, even though i am now able to map the relationship between the Auction lot and the parents (Sale and Session) the box for "Sale Data" which is a CPT Custo Field is still showing up, and is unpopulated.

Because the relationship is set, the data will be displayed in the view, however i am would like to know why the box is there: hidden link

#365057

Thank you for contacting Toolset support, I'd be delighted to assist!

I'm happy you got it figured out! I'm the only supporter in this timezone so I'm usually putting out several fires so I appreciate your patience with me 🙂

The 3rd box renders on the backend due to the way Toolset works, Parent fields will render in children so there is the possibility of it being entered for if a use case would require it. Apart from hiding it via CSS, I would recommend ignoring it.

Does that help, did I miss anything or am I off base?

#365346

HI Ross.

Thank for your reply.

I am ok with the box being there, however the problem is the data is not pulling through from it's parent.
Here is a screenshot of the Edit Auction Lot:
hidden link

You can see that the post relationship is set, however the "Sale Data" from the Sale CPT is not pulling through in the Edit screen, nor is it pulling through on the Single post of the Lot as seen below:
hidden link

The code for the view is simple as I havent started styling yet as I want to get this right first:

 
[types field="image" size="medium" align="none" resize="crop"][/types]
<p>[types field="write-up"][/types]</p>

<div>Sale Name: [types field="sale-name"][/types]</div>
<div>Auction Location: [types field="location"][/types]</div>
<div>Session: [types field="session-name"][/types]</div>
<div>Date: [types field="start-date"][/types] - [types field="end-date"][/types]</div>
<div>Dimensions: [types field="dimensions"][/types]</div>
<div>Condition: [types field="condition"][/types]</div>
<div>[types field="low-estimate" format="FIELD_NAME: FIELD_VALUE"][/types]</div>
<div>[types field="high-estimate" format="FIELD_NAME: FIELD_VALUE"][/types]</div>
<div>[types field="sold-unsold"][/types]</div>
<div>[types field="hammer-price" format="FIELD_NAME: FIELD_VALUE"][/types]</div>

Sale data is inputted in the Sale CPT:
hidden link

However is I scroll further down the page to the post relationship the same problem persists with linking Sale Data to Session Data hidden link

If I manually put the data in I am sure that it will show, however this is not an ideal solution.

You advice will be appreciated.

Josh

#365483

Question: Would it be more efficient to scrap the multiple CPT idea and just have all the required fields on the Auction Lot CPT?

#365492

It all depends on your use case! One thing is for sure, you can display the contents of the parent CPT with a specific shortcode:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

To include a field from the parent post, you would use the following shortcode:
[types field="xxxx" id="$yyyy"]
Where xxxx is the field of the parent you want to show, and yyyy is the slug-name of the parent. The “$?? is required, as this represents a variable where the parent post name will be replaced by the post ID, internally.

To auto populate a child's CPT fields from the parent's fields, you would need to write some PHP using the CRED API: https://toolset.com/documentation/user-guides/cred-api/ to pull data from parent CPT and place into child's fields.

#365520

Thank you. [types field="xxxx" id="$yyyy"] was the answer I was looking for.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.