Skip Navigation

[Resolved] Inherit image from parent CPT

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

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 2 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2147395

I have a CPT "Courses" that is the son of a CPT "Academies" the academies have a featured image that is their logo, I through parent-child relationship show the logo of the academy in the course template, but I need that when creating the This course, save the image that the parent academy has as an image. Is this possible? Thanks in advance

#2147571

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

You can use the "item" attribute, in Toolset shortcodes to show the post data (including the featured image) from the parent related post:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

For example, suppose that the post-relationship slug is "academies-courses", where the "academies" is the parent and the "courses" is the child post type.

In the content template for the "courses" post type, you can use the "wpv-post-featured-image" ( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-featured-image ) with the "item" attribute, to show the featured image from the parent "academies" posts:


[wpv-post-featured-image size="medium" item="@academies-courses.parent"]

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

regards,
Waqar

#2149439

Hello, thanks for the answer.
I understand that operation and I have it applied in my content template, but I need that when creating the child CPT it automatically saves its featured image using that of the parent CPT. Is this really possible?

#2149723

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

I'm afraid, there is no built-in feature available to achieve this, so it will require a fair amount of custom code.

For example, you can use the "save_post" hook, to execute a custom PHP function, when a child post is created from the post edit screen in the admin area:
https://developer.wordpress.org/reference/hooks/save_post/

If you're creating the child posts using the Toolset front-end forms, you can alternatively, use the "cred_save_data" hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

Note: Even if you manage to copy the featured image from the parent to child when a child post is created, keeping the featured image in sync will remain a challenge. If a featured image is changed for 1 parent post, you'll have to make sure to update it for all the child posts too. For this reason, it would be better to call the featured image directly from the parent, instead of saving it with the individual child posts too.

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