Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Displaying grandparent title of child post

$
0
0

I want to display the title of the grandparent of a child post within the child post view. My three custom post type slugs are as follows;

grandparent : 'listing'
parent : 'sell-list'
child : 'mycart'

I tried using the code from the following post http://wp-types.com/forums/topic/displaying-grand-parent-post-title-in-grand-child-post-view/ modified for my three slug names. So my code looks like this;

// Show grandparent post title in mycart results
function grand_parent_post_link_func( $atts ) {
extract( shortcode_atts( array(
'mycart_id' => 0,
), $atts ) );
if(!($mycart_id))
{
global $post;
$mycart_id = $post->ID;
}
$sell-list_id = get_post_meta($mycart_id, '_wpcf_belongs_sell-list_id', true);
$listing_id = get_post_meta($sell-list_id, '_wpcf_belongs_listing_id', true);
$res = '<a href="' . post_permalink( $listing_id ) . '">' . get_the_title($listing_id) . '</a>';
return $res;
}
add_shortcode( 'grand-parent-post-link', 'grand_parent_post_link_func' );

When I add the code to my functions.php, I don't get any website pages displayed so I must have made an error in the adaption of the coding. Could you have a look and advise please.

Regards

Robert


Viewing all articles
Browse latest Browse all 20145

Trending Articles