When I updated my Toolset plugin, the relationship custom fields are no longer showing with my custom PHP template. I have a CPT called "Product Showcase" it is related to another CPT "Company". After the update, the custom fields from the Showcase are still showing, but the custom fields for the related Company are no longer showing. I checked the support and couldn't find out how to convert my php code. Just ignore the part that is creating a slider. Here is the code that needs to be updated:
<!---Product Showcase Area Begins Here-->
<?php $posts = query_posts( $query_string . '&orderby=date&order=desc&post_type=product' ); ?>
<?php if( $posts ) : ?>
<h2 class="showcase">Product Showcase: <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h2>
<ul class="bxslider">
<?php while(have_posts()) : the_post(); ?>
<li>
<div class="slideInt">
<div class="showLeft"><?php echo types_render_field ("product-image"); ?></div>
<div class="showRight">
<p class="company"><?php echo types_render_field("company-name", array( "post_id"=>'$company')); ?></p>
<div class="phone"><?php echo types_render_field("main-phone-number", array( "output" => "html","post_id"=>'$company')); ?></div><div class="fullList"><a href="<?php $company_id = wpcf_pr_post_get_belongs(get_the_ID(), 'company'); echo get_permalink($company_id); ?>">Full Profile</a></div>
<?php echo types_render_field("product-description"); ?>
</div>
<div class="clearAll"></div>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; ?>
Please let me now what to do so these related custom fields will show again. Thank you!
Hi, if you used the migration tool in Toolset > Relationships to migrate to the new relationships system, this code should be updated. We have the new post relationships API documentation available here:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
I made some adjustments, and here's what I would like you to try:
<!---Product Showcase Area Begins Here-->
<?php $posts = query_posts( $query_string . '&orderby=date&order=desc&post_type=product' ); ?>
<?php if( $posts ) : ?>
<h2 class="showcase">Product Showcase: <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h2>
<ul class="bxslider">
<?php while(have_posts()) : the_post(); ?>
<?php $company = toolset_get_related_post(get_the_ID(), array('product', 'company'));?>
<li>
<div class="slideInt">
<div class="showLeft"><?php echo types_render_field ("product-image", array("id"=>$company)); ?></div>
<div class="showRight">
<p class="company"><?php echo types_render_field("company-name", array( "id"=>$company)); ?></p>
<div class="phone"><?php echo types_render_field("main-phone-number", array( "output" => "html","id"=>$company)); ?></div><div class="fullList"><a href="<?php echo get_permalink($company); ?>">Full Profile</a></div>
<?php echo types_render_field("product-description", array("id"=>$company)); ?>
</div>
<div class="clearAll"></div>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; ?>
Let me know the results and we can go from there.
Hi Christian,
Thanks for replying so quickly! I added your code, but it removed everything from the Product Showcase and left it empty. I added the old "product-image" and "product-description" code back because they are coming from the Product Showcase CPT, and were showing originally, so there was no problem there. My problem is that the company name and phone number (from the Company post type) aren't showing. I did do the migration before I submitted the original ticket, and got the message in the attached image, so I assume the Product Showcase is the child post type and the Company is the parent post type. If it helps, you can see the item here (along with the Enhanced Listing CPT above it that I am also having problems with.) hidden link
I really appreciate your help!
Hi Christian, I realized that you might have mixed up the parent - child relationship, so I just reversed them and viola! Thanks so much for taking the time to show me this. I would have never gotten it on my own. You're the best!
My issue is resolved now. Thank you!