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
| /** | |
| * Check before sorting your custom post type admin lists so you don't | |
| * override other changes. | |
| */ | |
| add_action( 'pre_get_posts', array( $this, 'admin_order_posts' ) ); | |
| public function admin_order_posts( $query ) { | |
| if( ( is_admin() && $query->is_admin ) && $query->get( 'post_type' ) == 'my_custom_post_type' ) { | |
| // This prevents other orderby options from breaking. |
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
| /** | |
| * Don't sort your custom post type admin lists this way because it will | |
| * override other sorting being executed on this list. | |
| */ | |
| add_action( 'pre_get_posts', array( $this, 'admin_order_posts' ) ); | |
| public function admin_order_posts( $query ) { | |
| if( ( is_admin() && $query->is_admin ) && $query->get( 'post_type' ) == 'my_custom_post_type' ) { | |
| $query->set( 'orderby', 'menu_order' ); | |
| $query->set( 'order', 'ASC' ); |
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
| /** | |
| * Load a .mo file for the old textdomain if one exists | |
| * | |
| * If you have to change your textdomain to comply with upcoming | |
| * plugin and theme repository standards, this function will check to | |
| * see if an old translation file exists and load it if it does, so | |
| * that people don't lose their translations. | |
| * | |
| * h/t: https://github.com/10up/grunt-wp-plugin/issues/21#issuecomment-62003284 | |
| */ |
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
| /** | |
| * I'm going to add some content from one post to | |
| * the content of another post. Yay for me. | |
| */ | |
| add_filter( 'the_content', 'my_little_content_addition' ); | |
| function my_little_content_addition( $content ) { | |
| if ( is_the_right_content() ) { | |
| /** |
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
| /** | |
| * Let's say you're parsing query args in the admin so | |
| * that you can apply some custom filters for your | |
| * custom post type list table. | |
| */ | |
| add_filter( 'parse_query', 'filter_my_post_type' ); | |
| function filter_my_post_type( $query ) { | |
| /** | |
| * Oh good, you've put in that is_admin() check |
NewerOlder