Skip to content

Instantly share code, notes, and snippets.

@wplit
Last active February 5, 2026 23:01
Show Gist options
  • Select an option

  • Save wplit/e8c29433584318588f30d79972a4fa5a to your computer and use it in GitHub Desktop.

Select an option

Save wplit/e8c29433584318588f30d79972a4fa5a to your computer and use it in GitHub Desktop.
Add admin column to show favorited count next to each post, change 'product' to any post type
<?php
// Array of post types to include the column
function x_favorite_post_types() {
return [
'product' /* product post type */
];
}
// Add custom column
add_filter('manage_posts_columns', 'x_add_favorited_users_column');
function x_add_favorited_users_column($columns) {
$screen = get_current_screen();
if (!$screen || !in_array($screen->post_type, x_favorite_post_types(), true)) {
return $columns;
}
$columns['favorited_users'] = 'Favorited Count'; /* title of column */
return $columns;
}
// Output column value
add_action('manage_posts_custom_column', 'x_show_favorited_users_column_content', 10, 2);
function x_show_favorited_users_column_content($column, $post_id) {
if ($column !== 'favorited_users') {
return;
}
echo (int) bricksextras_post_favorite_count($post_id);
}
@wplit
Copy link
Author

wplit commented Feb 5, 2026

SCR-20260206-jczj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment