WordPress.org

Forums

In admin, how can I say what custom post type I'm editing? (2 posts)

  1. stratboy
    Member
    Posted 3 years ago #

    Hi! In admin, how can I say what custom post type I'm editing?

    I need it mainly because I'm building custom post types with custom meta boxes and want to modify the tinymce editor ONLY fo that specific custom post type creation/edit pages.

    Is an id or name of the custom post type stored somewhere?

    Thank you!

  2. stratboy
    Member
    Posted 3 years ago #

    Found an answer by myself. Anyway, I'd really like if someone could tell me if it's a good way to achieve my goal or not.

    $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : (isset($_GET['post']) ? get_post_type($_GET['post']) : null );

    I place this code in a funcion called by 'load-post.php' and 'load-post-new.php' hooks. I can then see if $post_type is == 'my_custom_post_name'. It works.

    The reason of the chained compressed if statement is that in the 'post-new.php' page I've got $_GET['post_type'], while in the 'post.php' page I can't get it directly (at least it seems so.. There's no $_GET['post_type']), but I can get the post_type by passing the ID to get_post_type, and I get that ID with $_GET['post'].

    OK. So, again, is this a good practice? Am I doing it the right way?

Topic Closed

This topic has been closed to new replies.

About this Topic