Last active
February 5, 2026 23:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } |
Author
wplit
commented
Feb 5, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment