Hi there,
I have a custom post and on it a custom field we'll call Display. The Display field is a checkbox, and it holds a value of 1 when checked and 0 when not checked.
On the admin posts screen, the Display column appears and outputs either 1 or 0. What I would like to do is modify the output of the column. If the value of Display is 1, I want to output a checkmark icon. If the value of Display is 0, I want to output nothing.
I've read extensively about adding custom columns to custom post admin screens and populating their content and done this many times on many sites, but I'm having trouble modifying the existing value of a custom field. When I hook into manage_{$post_type}_posts_custom_column, I can only seem to print a second value in the column, but I can't replace the content. In other words, the output in the Display field is "1checkmark". The "1" is the value in the database, and "checkmark" represents the checkmark icon that I've coded.
Here's a snippet of the relevant code I'm using:
function car_resource_columns_output ( $column_name, $post_id ) {
switch ( $column_name ) {
case 'wpcf-display':
$field_value = get_post_meta( $post_id , $column_name , true );
if ( $field_value == '1') {
printf ('<span class="dashicons dashicons-yes"></span>') ; // checkmark
}
break;
}
}
add_action ( 'manage_resource_posts_custom_column', 'car_resource_columns_output', 100, 2 ) ;
If "Display" is 1 is the database, the output in the admin posts screen is this:
1<span class="dashicons dashicons-yes"></span>
In Query Monitor, I can see that the manage_resource_posts_custom_column hook is being called twice: once by Toolset, and once by my code.
One solution might be to hide the "real" Display field and create my own field. But is there a proper way to just modify the field value?
Thank you!
Saul