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 you can set your query inside.
There is also another approach for this. By using is_post_type_archive('custom_job')
, you can target the edit.php?post_type=custom_job
. Make sure you use this in conjunction with is_admin()
to make sure you don’t target the front-end.
Related Posts:
- single-{$post_type}-{slug}.php for custom post types
- Row actions for custom post types?
- remove custom post type permalink
- Saving Taxonomy Terms
- Filter by custom field in custom post type on admin page
- How can I remove the “Add New” button in my custom post type?
- Media library – Limit images to custom post type
- Sort search results by post type
- Prevent pre_get_posts filter on specific post type
- How to order posts of a custom post type by date DESC in dashboard Admin?
- How to remove Filters from post admin page?
- Custom sortable columns ordered by meta-value?
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- How can I filter posts by post_parent in the admin?
- $query->set in pre_get_posts is unintentionally affecting the backend
- How do I filter the excerpt metabox description in admin?
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- Filter for “get_post_type_archive_link()”
- How to correctly get post type in a the_title filter
- How to put custom post types on front page
- How to add a CSS class to every image in a Custom Post Type
- Best way to filter featured image text for a custom post type?
- How can I get next/ previous post links to order by a filter (by the last word of the title)?
- Add Custom Post Type to Current Query
- How to show more posts on an archive page?
- Include post id[s] into WP_Query()
- Pre get posts for single post
- Filter by custom Field for Custom post type Admin Listing
- Most efficient way to search for values from CPT in Post content
- WP Admin default view mode for Custom Post Type
- How to get my Custom Post Type to display in Recent Posts using “pre_get_posts”
- post_type_link filter causes 404 on the CPT page it’s used on
- Remove wpautop from all posts/pages except my custom post type
- Remove date and category filters when editing custom post types
- Pre_get_posts Gives 404 on Custom Post Type
- Taxonomy terms with edit/filter link in wp-admin, in the list of custom posts
- Meta query broken since 4.7.4 Update
- What’s the most efficient way to get two queries based on an if statement?
- Add filter button to custom post type in admin area
- Enable shortcodes on custom post type
- Filter between Custom Posts depending on meta_value
- Grouping and paging CPT events by month with custom field date
- Highlight a Post on archive page if it has a new comment?
- Creating adminable dynamic filtering on custom post type
- Pre_get_posts comparison with custom field doesn’t work
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- Custom Post Search
- Adding Information To All Posts Screen
- Menu disappears with custom post type link
- Dropdown switching subcategories portfolio
- Filter Content on all Post Types
- Filter wp_dropdown_categories Per Post Type
- Custom post type with Filter and Page Nav
- pre_get_posts with multiple post types AND a meta_key
- Sorting on Taxonomy in archive page
- Converting a checkbox filter for custom fields to a dropdown
- add current-menu-item to multiple custom post types
- Filter custom post type by tags
- pre_get_posts not firing at all
- Custom Search Template for Custom Post Types
- Fetch post meta in the same query as the main loop
- Exclude Custom Post Type from shared Custom Taxonomy
- Problem to show custom post type in archive page category wise
- Using $seed on a custom post type for randomly displayed posts
- using ACF datepicker to filter posts on a page
- Adding custom post types to the default loop, yet only posts that has terms from the core taxonomies
- Hook only specific post type
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Restrict a filter to a custom post type. Am I doing this right?
- How do I sort post listing by child post count?
- Diffrent search templates for different post types
- pre_get_posts action doesn’t work
- custom post types, pre_get_posts, wp_list_categories
- How to filter posts by categories?
- How do I filter a custom post type loop by a field?
- A to Z list for custom post types
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- add_filter > posts_where works partially
- Simple Share Buttons Add Plugin and Custom Post Type
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Trying to set up a range filter for related custom post types
- Filter page ID outside the loop and order
- When Attempting to Filter Plugin Generated Content Using Filter post_type_link, Permalinks Are Not Modified
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- Paginate yearly archives for a custom post type
- Change CPT Edit Target Link for Admin List
- Sorting by Title for Post Archive Categories for Custom Post Type
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template
- How can I incldue a “private” post type in a loop for public users?
- Add post id to url instead of WordPress default -2 suffix
- coloring row’s background based on custom field value
- Custom post type template not loading from plugin
- Show only taxonomy types terms associated with a custom post type in WordPress PHP
- How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?
- Search for portfolio tags & mixing portfoliotags and post tags
- Modify wp_title for custom post types using custom fields data?
- How do I add a filter to my custom post type archive page?
- How to Filter the Custom term loop based on dropdown
- How to set up a private custom post type that is accessible in the administrative dashboard?