Created
July 21, 2026 02:59
-
-
Save wplit/e20bbe48830efc75b14a1b178786cfdb to your computer and use it in GitHub Desktop.
Example: Add 'Favorited Count' column to products list
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
| // 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'; | |
| 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
commented
Jul 21, 2026
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment