Hi, I found this code for displaying admin column for parent post title from the following thread:
https://toolset.com/forums/topic/how-to-get-wordpress-admin-columns-for-parent-post-title/
I copied it over and changed around the code for my site's CPT's, the column was created and is displaying, but for some reason I keep getting the "else" message of "No Maggid Shiur", even when I know there is a related parent post title. (see images below)
Do you see any issue with the code?
//Add custom column
add_filter('manage_edit-shiur_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['Parent'] = 'Maggid Shiur';
return $defaults;
}
//Add rows data
add_action( 'manage_shiur_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
switch ( $column ) {
case 'Parent':
$parent_id = get_post_meta( $post_id, "_wpcf_belongs_person_id", true);
if($parent_id){
echo get_the_title( $parent_id );
} else {
echo 'No Maggid Shiur';
}
break;
}
}
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Thank you for getting in touch.
The problem here is that this method is using the old method of getting the relationship and will no longer work after installing types 3.0
To get this working again it will need to be modified with the function below.
toolset_get_related_post()
Try using this code.
//Add custom column
add_filter('manage_edit-shiur_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['Parent'] = 'Maggid Shiur';
return $defaults;
}
//Add rows data
add_action( 'manage_shiur_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( 'person', 'shiurim' ) );
if($parent_id){
echo get_the_title( $parent_id );
} else {
echo 'No Maggid Shiur';
}
break;
}
}
You may need to replace "shiurim" with the actual correct slug for the post type.
Please let me know if this helps.
Thanks,
Shane
Hi Shane,
Thanks for getting back to me so soon. I swapped out the code and changed the 'shiurim' to 'shiur' on this line (shiur is the slug name): $parent_id = toolset_get_related_post( $post_id, array( 'person', 'shiur' ) );
But when I save the functions.php file it is still showing up as "No Maggid Shiur".
Any ideas?
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
This is going to require some further debugging.
Would you mind allowing me to have admin access to the site to check on this in further details for you ?
I've enabled the private fields for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Sim,
Checking this it appears the "No Maggid Shiur" is appearing under posts where there isn't any Parent.
From what I can see the code is working as intended as the name of the parent shows up for posts that have parents.
Thanks,
Shane
Not sure why when I tested it earlier it wasn't displaying.. perhaps it was a simple caching issue. Either way, I double checked and I see it working now, so thanks.
My issue is resolved now. Thank you!