[Resolved] Custom fields not displaying in Content Template
This thread is resolved. Here is a description of the problem and solution.
Problem: I have two custom post types in a parent/child relationship. On the child single post Content Template, I include some information from the parent post by inserting another Content Template. Then after the parent post information I want to show custom fields from the child post. However, the custom fields do not appear, and the post context appears to remain the parent post.
Solution: Instead of inserting the parent post Content Template directly into the child post Content Template, use a View filtered by post ID, supplied by a shortcode attribute. Then insert your parent post Content Template in the Loop Output of this nested View.
0% of people find this useful.
This support ticket is created 6 years, 2 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.
My client is an Educational Agency that offers courses for companies, freelances, professional schools and private people.
I am using Toolset and Divi theme for this project to create a Course Managing website. This is the second ticket that I am opening for this project I can provide a link to the first ticket if needed.
I have this situation.
CPT ANAGRAFICA CORSI (course catalog)
CPT AGENDA CORSI ( course sessions)
TAX AREE RIFERIMENTO (course scope area)
RELATIONS
AGENDA CORSI is child of ANAGRAFICA CORSI (which has AREE RIFERIMENTO taxonomy connected)
THEME : DIVI (latest version as of Feb 16th 2018)
Wordpress :4.9.4
To display the COURSE SESSION the way I wanted I created a single-sessione-corso.php page from single.php in the DIVI child theme folder and customised it.
1. I am creating a content template for COURSE SESSION to display a single occurrence of each course in the COURSE CATALOG, without having to repeat redundant fields in the child CPT, so I would like to take the Course Description from the parent Course and display it in the content template. In a DIVI TEXT module I am inserting a placeholder and a field from the Course Session CPT but nothing is showing (see image1 red area) while the course description (which is a field belonging to the PARENT anagrafica corso) is displaying without any problem.
DATA DI PARTENZA : [types field="data-di-partenza" style="text" format="j F Y"][/types]
DATA TERMINE ISCRIZIONI : [types field="termine-iscrizioni" style="text" format="j F Y"][/types]
QUOTA DI PARTECIPAZIONE : [types field="quota-partecipazione"][/types]
What am I doing wrong?
2. The parent course has a particular taxonomy assigned (area di riferimento) which has a few custom fields (icon and header. I would like to insert the taxonomy header image above the Course title, as shown in Image1.
To display the COURSE SESSION the way I wanted I created a single-sessione-corso.php page from single.php in the DIVI child theme folder and customised it.
Please share the code or a download link to this file for me to review.
1. In a DIVI TEXT module I am inserting a placeholder and a field from the Course Session CPT but nothing is showing
Please add a post ID shortcode that will help determine the post context when the types field shortodes are executed:
Post ID: [wpv-post-id]
DATA DI PARTENZA : [types field="data-di-partenza" style="text" format="j F Y"][/types]
DATA TERMINE ISCRIZIONI : [types field="termine-iscrizioni" style="text" format="j F Y"][/types]
QUOTA DI PARTECIPAZIONE : [types field="quota-partecipazione"][/types]
2. The parent course has a particular taxonomy assigned (area di riferimento) which has a few custom fields (icon and header. I would like to insert the taxonomy header image above the Course title, as shown in Image1.
This sounds like a different question, so may I kindly ask you to create a separate ticket? This will help keep the forum organized, and help other users find answers to similar questions.
As this is the most complicated project I have had to deal with so far, I have quite a few issues that I am trying to solve one by one as they pop up. Sorry for all the tickets I am opening, but I am learning a great deal. I will open a new ticket for the taxonomy term issue, thank you.
Okay it looks like post ID 50132 is the parent Anagrafica Corsica. So for some reason, this section of the Content Template has the parent post context. Would it be possible for you to share login credentials with me so I can see how this is configured? Please let me know where I can find the Content Template in wp-admin. I have activated private reply fields here.
Okay thanks. I opened this Content Template: hidden link
I clicked "Edit with Divi Builder" and looked in the 2nd row, right column. There is a post body shortcode with the parent anagrafica-corso post ID applied:
If I remove that wpv-post-body shortcode, the correct information begins to appear below. So I need to do a bit more investigation to determine why the parent post content seems to be resetting the context below it. May I install the Duplicator plugin and create a clone of your site so I can investigate further without affecting your live site?
Dear Chris, please do all the necessary steps to find out what is going on. I had to put the Id=$anagrafica-corso in order to be able to retrieve the course description, which is -of course- saved in the course catalog post type and not the course session which is a mere instance of it. I will be waiting for the results of your investigations. Thank you for your help!
Okay after a few modifications I have this working better now.
- I created a new View of Anagrafica Corsi, filtered by post ID, set by a shortcode attribute: hidden link
- In that View, I placed a wpv-post-body shortcode to display the parent Anagrafica Corso post
- Edited the Scheda Sessione Corso Content Template in Divi Builder: hidden link
- I deleted this code:
There was a problem with the nesting of Content Templates that can be resolved by using one additional View to show the parent post's content. Please check here and let me know what you think: hidden link
Dear Chris,
thanks for your solution. I was wondering : is this problem caused by the fact that I am creating the content template via the Divi Builder?
Actually no, in my local testing I activated Twenty Seventeen and deactivated all plugins except Types and Views, but the problem continued to occur. It's more related to the overall organization of the content on this page, and the use of multiple Content Templates that somehow modify the post context when they are executed. The use of an extra View helps specify post context in an explicit way that prevents that implicit context swapping.
Ok, thank you very much for your help. I have to carefully review the solution in order to understand completely how you came to solve this problem, because the nested view concept is not completely clear to me.
Thanks again for your help!
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.