Menü schliessen
Created: August 17th 2013
Last updated: May 1st 2020
Categories: Wordpress
Author: Marcus Fleuti

Wordpress (custom) Posts :: Find out the post_type of the current editing (custom) post

Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

Usecase

When you work with additional functions like custom meta boxes within custom post types you might want to find the post_type of the current editing post. For example to work with only 1 metabox for different post types and add/remove certain elements depending on the post. Starting from WordPress 3.3 it's quite easy to fulfill this but it's hard to find this information online. So I hope I can help you out a little.

Howto

Just add the following function within your functions.php:

function get_wpadmin_post_type() {
    $screen = get_current_screen();
    $post_type = $screen->id;
    return $post_type;
}

Now you can simply callup this function from within any other function to get the post_type. I am sure you know how to do that 😉