Skip Navigation

[Closed] Display fields of post parent within loop

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 9 replies, has 3 voices.

Last updated by Pratley 11 years, 7 months ago.

Assisted by: bruce.

Author
Posts
#13378

There is no problem with composing a view like "parent page - list of child pages" created using the post relation feature
But how can I do the opposite - display the title and other fields of the post's parent within a loop of children?
For example I have "events" as parents and dates (with a bunch of their fields) as children. So i want to display a list of all dates with the title of the event that they belong to showing up next to each date. Grouping them by parent doesn't do because I need them ordered by date.

#13383

Hi Anna,

To do this you can add the id and post type to the field you want to display.
eg [wpv-post-title id="$event"] will display the event title that is the parent of the date.

https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

Best regards,
Bruce.

#19979

Is there a way of doing this using the Types API rather than via Views? I dug about and found the wpcf_pr_post_get_belongs function but can't get any further than that.

#20023

Hi Stephen,

You can try calling do_shortcode to call it from php:

echo do_shortcode('[wpv-post-title id="$event"]');

Or you can use the WPV_wpcf_switch_post_from_attr_id class.

$atts = array('id' => '$event');
$post_id_atts = new WPV_wpcf_switch_post_from_attr_id($atts);
echo types_render_field('my-field');
delete $post_id_atts;

The id will stay switched until $post_id_atts is deleted.

Best regards,
Bruce

#20077

Just getting the title of the child post

I'm doing this within a genesis framework site that has parents with a post type of "site" and offers with a post type of "offer"

Here's the whole code - I have a list of offers on the homepage and I want to show the site they are connected to (post title) and also, eventuially, the link to that site which is a custom field "site_destination_url" in the parent post also.

remove_action('genesis_loop', 'genesis_do_loop');//remove genesis loop
add_action('genesis_loop', 'home_loop');//add the home loop
 
function home_loop() {
 
    $loop = new WP_Query( array( 'post_type' => 'offer', 'posts_per_page' => 20 ) ); ?>

    	<div id="offers">
	<h1>Latest Offers</h1>
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                <h2><?php the_title(); ?></h2>
		<p><?php the_excerpt(); ?></p>
		<? echo do_shortcode('[wpv-post-title id="$site"]'); ?>
    	<?php endwhile;?>
	</div>
    <?php
    }
 
    genesis();
#20085

Hi Stephen,

Try adding the following call before calling do_shortcode. It will record the related posts needed.

<?php WPV_wpcf_record_post_relationship_belongs(''); ?>

Best regards,
Bruce

#20088

Bruce, I've bought and installed Views and am getting a step closer but getting myself more and more confused!

I'm just moving to WP for from ExpressionEngine so I know what I want and how the data hangs together and is related, but am at the bottom of steep learning curve!

Would you be interested in a few hours to help get the site basics in order for me?
It's just the homepage listing and a search listing page I need sorting out in a similar manner to my existing site pages which are OK now.

How could I get in touch?

#20166

Hi Stephen,

I'm sorry but we can't offer service by the hour. Please ask for specific help on the support forum and we should be help you with these issues.

Best regards,
Bruce

#20333

OK, thanks Bruce, getting there step by step 🙂
I'm now outputting the parent title nicely using your code above.

How do I find out the fieldnames for the rest of the standard fields (looking for the slug in particular), and also how to form the fieldnames to show custom fields from the parent(I have one called site-destination-url).

#20337

Found most of what I need in the documentation but it could do with a couple of examples.

The topic ‘[Closed] Display fields of post parent within loop’ is closed to new replies.