Skip Navigation

[Resolved] Link to Parent Relationship in the grid

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to display the title of a parent post in The Grid.

Solution: The standard post relationship shortcodes do not work well in The Grid. Try this custom shortcode instead:

add_shortcode( 'ts-get-parent-artist', 'ts_get_parent_artist_func');
function ts_get_parent_artist_func( $atts, $content ) {
  $a = shortcode_atts( array(
      'child' => '0',
      'type' => 'artist',
  ), $atts );
  $parent = toolset_get_related_post( $a['child'], 'artist-release' );
 
  return get_the_title($parent);
}

Then add this to The Grid:

[ts-get-parent-artist child="#post_ID#"]

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This support ticket is created 5 years, 4 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.

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 16 replies, has 2 voices.

Last updated by chrisC-25 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1147450

Okay that helps a bit. I can give you a custom shortcode that will display the parent post title. I added this code to your child theme's functions.php file:

add_shortcode( 'ts-get-parent-artist', 'ts_get_parent_artist_func');
function ts_get_parent_artist_func( $atts, $content ) {
  $a = shortcode_atts( array(
      'child' => '0',
      'type' => 'artist',
  ), $atts );
  $parent = toolset_get_related_post( $a['child'], 'artist-release' );

  return get_the_title($parent);
}

Be sure to pull that update down to your local file repository.

Then I added the shortcode to your skin like this:

[ts-get-parent-artist child="#post_ID#"]

Now the parent post title is displayed in the skin. The problem with this approach is that it's not very flexible. For instance, if you want to display the parent post URL, the parent post link, custom fields from the parent post, etc, it will require a separate custom shortcode for each one. I wasn't able to figure out a way to return the parent post ID and then use that in another shortcode attribute. That would take some more investigation and may or may not be possible.

#1148065

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.