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?
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
My issue is resolved now. Thank you!