Apply pre_get_posts to specific custom post type in the admin area

The function you are looking for is get_current_screen(). To check if you are on a specific custom post type page, do as follows: $screen = get_current_screen(); if ( $screen->post_type == ‘custom_job’ ) { // We are on custom_job post type, good to go } Now, if you visit edit.php?post_type=custom_job, this conditional will return true, which … Read more

Get First Post content and edit it using pre_get_posts (or similar?!)

You can use the loop_start hook which passes the $WP_Query object by reference. namespace StackExchange\WordPress; class editFirstPostContent { public function load() { if( \is_admin() ) { return; } \add_filter( ‘loop_start’, [ $this, ‘loopStart’ ] ); } public function loopStart( \WP_Query $WP_Query) { if( ! $WP_Query->is_main_query() ) { return; } if( ! isset( $WP_Query->posts[0] ) ) … Read more