//Additional Admin Column Experts
add_filter('manage_expert_posts_columns', 'c2_filter_posts_columns');
function c2_filter_posts_columns($columns)
{
$columns['related_talks'] = __('Related Talks', 'experts');
$columns['related_gifts'] = __('Related Gifts', 'experts');
$columns['related_sponsors'] = __('Related Sponsors', 'experts');
return $columns;
}
add_action('manage_expert_posts_custom_column', 'c2_related_info_column', 10, 2);
function c2_related_info_column($column, $post_id)
{
// Related Talks column
if ('related_talks' === $column) {
get_post_column_data($post_id, 'talk');
}
// Related gifts column
if ('related_gifts' === $column) {
get_post_column_data($post_id, 'gift');
}
// Related sponsors column
if ('related_sponsors' === $column) {
get_post_column_data($post_id, 'sponsor');
}
}
function get_post_column_data($c_post_id, $post_type)
{
$num_count = 0;
$ass_ex = array(
'post_type' => $post_type,
'separater' => ', ',
'meta_query' => array(
array(
'key' => '_cb_gifts',
'value' => $c_post_id,
'compare' => 'LIKE',
)
)
);
$queryex = new WP_Query($ass_ex);
$num_of_items = $queryex->found_posts;;
if ($queryex->have_posts()) {
while ($queryex->have_posts()) {
$queryex->the_post(); ?>
<a href="<?php echo get_edit_post_link(get_the_ID()); ?>">
<?php the_title(); ?>
</a>
<?php
$num_count = $num_count + 1;
if ($num_count < $num_of_items) {
echo ", ";
}
}
wp_reset_postdata();
} else {
_e('—');
}
}
Jagdish Sarma Asked question April 1, 2023