Created
December 16, 2025 07:20
-
-
Save marklchaves/e6acaf5fbbfac9279e0c17ad416b4352 to your computer and use it in GitHub Desktop.
Custom PHP code that makes Popup Maker's Enabled column sortable
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 | |
| /** | |
| * Make Popup Maker's Enabled column sortable | |
| */ | |
| // Add 'enabled' to sortable columns | |
| add_filter( 'manage_edit-popup_sortable_columns', function( $columns ) { | |
| $columns['enabled'] = 'enabled'; | |
| return $columns; | |
| }, 20 ); | |
| // Handle the sorting logic for the enabled column | |
| add_filter( 'request', function( $vars ) { | |
| // Check if we're viewing the "popup" post type | |
| if ( isset( $vars['post_type'] ) && 'popup' === $vars['post_type'] ) { | |
| // Check if we're sorting by 'enabled' | |
| if ( isset( $vars['orderby'] ) && 'enabled' === $vars['orderby'] ) { | |
| $vars = array_merge( | |
| $vars, | |
| [ | |
| 'meta_key' => 'enabled', | |
| 'orderby' => 'meta_value_num', | |
| ] | |
| ); | |
| } | |
| } | |
| return $vars; | |
| }, 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment