Opened 13 years ago
Closed 13 years ago
#21561 closed feature request (wontfix)
is_page_template() doesn't work in admin edit page screen
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | trivial | Version: | 3.4.1 |
Component: | Template | Keywords: | |
Focuses: | Cc: |
Description
Take this use case scenario:
I want to show a meta box on the page edit screen when a certain template is set.
To do the above I'd use some code like this:
public static function add_meta_boxes( $post_type, $post ) { if( "page" != $post_type ) return; if ( ! is_page_template('templates/with-solutions.php') ) return; add_meta_box("bs_SolutionsMeta-meta", "Solutions", array( __CLASS__, "solutions_meta" ), "page", "normal", "low"); }
Unfortunately the above won't work as is_page_template() does an is_page() check in its function which will fail when run in admin.
I'd like to propose that the function be worked on to allow this function work in the admin some way.
I have found a work around and used:
if ( 'templates/with-solutions.php' != get_page_template_slug( $post->ID ) ) return;
for now but I'd love to see that function functional in admin.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Using template tags does not make sense in the admin. I think your workaround is more along the proper method but I would use get_post_meta($post->id, '_wp_page_template');