I’d like to show the post type of a post, you can do that with get_post_type(), but in my case the names are not pretty (for ex : p_project_plans). So instead I thought I’d show the asociated “menu_name” (as declared with register_post_type), which looks much nicer (for ex : Project plans).
Is there a way to do that ?
Hi @mike23:
This code shows you how to get both singular and plural names (assuming you specified them as such in your register_post_type()
).
Note that the code example is presented as a standalone file you can save as test.php
file in the root of your website and load in your browser with http://yoursite.com/test.php
(assuming you replace yoursite.com
with your site’s domain!):
<?php
/*
Filename: test.php
*/
include( '../wp-load.php' );
header( 'Content-type:text/plain' );
$post_type_object = get_post_type_object('p_project_plans');
echo "Singular: {$post_type_object->labels->singular_name}\n";
echo "Plural: {$post_type_object->labels->name}\n";