Skip Navigation

[Resolved] Display Admin Column for Related Parent in WP Admin

This support ticket is created 3 years, 3 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Sean Ramsey 3 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2348945

Tell us what you are trying to do?
I'm trying to implement this code: https://toolset.com/forums/topic/display-admin-column-from-related-parent-post-title/ so that I can display the parent post name in the WP Admin column on the child view.

The parent slug is 'partner-organization'
The child slug is 'service-provider'
The column name should be 'Partner Name'

Here is the code with my updates:

//Replace the following
/*
cptslug - replace with custom post type slug
parent - replace with parent cpt slug
child - replace with child cpt slug
Column Name - replace with the desired column name.
*/

//Add custom column
add_filter('manage_edit-service-provider_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['Parent'] = 'Partner Name'; //edit
return $defaults;
}

//Add rows data
add_action( 'manage_service-provider_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
switch ( $column ) {
case 'Parent':
$parent_id = toolset_get_related_post( $post_id, array( 'partner-organization', 'service-provider' ) );
if($parent_id){
echo get_the_title( $parent_id );
} else {
echo 'No Parent Found';
}
break;
}
}

The column is getting created on the CPT service-provider layout. All records have the same parent but they are all showing 'No Parent Found' in the column. I am trying to get it to display the name of the Parent (i.e. partner-organization)

What am I missing?

#2348959

Shane
Supporter

Languages: English (English )

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

Hi Sean,

Thank you for getting in touch.

Can you try changing the array( 'partner-organization', 'service-provider' ) in the toolset relationship function to just using the relationship slug on ?

Meaning it should be like this
toolset_get_related_post( $post_id, "relationship-slug" ) )

Thanks,
Shane

#2348963

My issue is resolved now. Thank you!