Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 3 voices.

Last updated by Silvia 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#616747
image1.jpg

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.

Thank you!

#617164

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.

#617196

Chris, thanks for your answer.

1) Here is the code in the single-sessione-corso.php page

<?php
get_header();
echo do_shortcode('[et_pb_section global_module="50410"][/et_pb_section]');
$show_default_title = get_post_meta( get_the_ID(), '_et_pb_show_title', true );
$is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
?>
<div id="main-content">
	<?php
		if ( et_builder_is_product_tour_enabled() ):
			// load fullwidth page in Product Tour mode
			while ( have_posts() ): the_post(); ?>

				<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
					<div class="entry-content">
					<?php
						the_content();
					?>
					</div> <!-- .entry-content -->

				</article> <!-- .et_pb_post -->

		<?php endwhile;
		else:
	?>
	<div class="container-fluid">
		<div id="content-area" class="clearfix">
			<div id="left-area">
			<?php while ( have_posts() ) : the_post(); ?>
				<?php if (et_get_option('divi_integration_single_top') <> '' && et_get_option('divi_integrate_singletop_enable') == 'on') echo(et_get_option('divi_integration_single_top')); ?>
				<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
					<?php if ( ( 'off' !== $show_default_title && $is_page_builder_used ) || ! $is_page_builder_used ) { ?>
						<div class="et_post_meta_wrapper">
							<!--<h1 class="entry-title"><?php the_title(); ?></h1>-->
						<?php
							if ( ! post_password_required() ) :

								//et_divi_post_meta();

								$thumb = '';

								$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );

								$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
								$classtext = 'et_featured_image';
								$titletext = get_the_title();
								$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
								$thumb = $thumbnail["thumb"];

								$post_format = et_pb_post_format();

								if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) {
									printf(
										'<div class="et_main_video_container">
											%1$s
										</div>',
										$first_video
									);
								} else if ( ! in_array( $post_format, array( 'gallery', 'link', 'quote' ) ) && 'on' === et_get_option( 'divi_thumbnails', 'on' ) && '' !== $thumb ) {
									print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height );
								} else if ( 'gallery' === $post_format ) {
									et_pb_gallery_images();
								}
							?>

							<?php
								$text_color_class = et_divi_get_post_text_color();

								$inline_style = et_divi_get_post_bg_inline_style();

								switch ( $post_format ) {
									case 'audio' :
										$audio_player = et_pb_get_audio_player();

										if ( $audio_player ) {
											printf(
												'<div class="et_audio_content%1$s"%2$s>
													%3$s
												</div>',
												esc_attr( $text_color_class ),
												$inline_style,
												$audio_player
											);
										}

										break;
									case 'quote' :
										printf(
											'<div class="et_quote_content%2$s"%3$s>
												%1$s
											</div> <!-- .et_quote_content -->',
											et_get_blockquote_in_content(),
											esc_attr( $text_color_class ),
											$inline_style
										);

										break;
									case 'link' :
										printf(
											'<div class="et_link_content%3$s"%4$s>
												<a href="%1$s" class="et_link_main_url">%2$s</a>
											</div> <!-- .et_link_content -->',
											esc_url( et_get_link_url() ),
											esc_html( et_get_link_url() ),
											esc_attr( $text_color_class ),
											$inline_style
										);

										break;
								}

							endif;
						?>
					</div> <!-- .et_post_meta_wrapper -->
				<?php  } ?>

					<div class="entry-content">
					<?php
						do_action( 'et_before_content' );

						the_content();

						wp_link_pages( array( 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'Divi' ), 'after' => '</div>' ) );
					?>
					</div> <!-- .entry-content -->
					<div class="et_post_meta_wrapper">
					<?php
					if ( et_get_option('divi_468_enable') == 'on' ){
						echo '<div class="et-single-post-ad">';
						if ( et_get_option('divi_468_adsense') <> '' ) echo( et_get_option('divi_468_adsense') );
						else { ?>
							<a href="<?php echo esc_url(et_get_option('divi_468_url')); ?>"><img src="<?php echo esc_attr(et_get_option('divi_468_image')); ?>" alt="468" class="foursixeight" /></a>
				<?php 	}
						echo '</div> <!-- .et-single-post-ad -->';
					}
				?>

					<?php if (et_get_option('divi_integration_single_bottom') <> '' && et_get_option('divi_integrate_singlebottom_enable') == 'on') echo(et_get_option('divi_integration_single_bottom')); ?>

					<?php
						if ( ( comments_open() || get_comments_number() ) && 'on' == et_get_option( 'divi_show_postcomments', 'on' ) ) {
							comments_template( '', true );
						}
					?>
					</div> <!-- .et_post_meta_wrapper -->
				</article> <!-- .et_pb_post -->

			<?php endwhile; ?>
			</div> <!-- #left-area -->

			<!-- <?php get_sidebar(); ?>-->
		</div> <!-- #content-area -->
	</div> <!-- .container -->
	<?php endif; ?>
</div> <!-- #main-content -->

<?php get_footer(); ?>

2) I did as you instructed and inserted a Post_id shortcode in the content template. Here you can find the result : hidden link

Waiting for your feedback. Please note that I had already opened a ticket for this website I am working on, so if you need to access the backoffice for some reason, feel free to do it, the login info are in this thread https://toolset.com/forums/topic/build-taxonomy-archive-page-with-divi-builder/.

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.

#617563

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Silvia,

Christian is currently on Holiday today but he will be back tomorrow to continue this thread with you.

Thanks,
Shane

#617918

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.

#618079

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:

{!{wpv-post-body view_template="None" id="$anagrafica-corso"}!}

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?

#618081

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!

#618266

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:

{!{wpv-post-body view_template="None" id="$anagrafica-corso"}!}

- I replaced it with the View I created before, and supplied the parent Anagrafica Corso post ID in the shortcode attribute "ids":

{!{wpv-view name="parent-anagrafica-corso" ids="{!{wpv-post-id id='$anagrafica-corso'}!}"}!}

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

#618465

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?

#618723

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.

#618806

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.