Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress get custom post type label name

I want to echo a custom post type lable/Menu_name.

Example:

I create custom post type named: Product

In product post type I add post Ice Cream.

So I want to echo in ice cream page this example link:

Home/product/Icecream

Basically its like breadcrumb for custom post type.

like image 468
Abdullah Avatar asked Jul 06 '12 07:07

Abdullah


2 Answers

Get the post_type object to get the labels' singular_name or plural name,

$post_type_obj = get_post_type_object( 'ice_cream' );
echo $post_type_obj->labels->singular_name; //Ice Cream.
echo $post_type_obj->labels->name; //Ice Creams.
like image 180
Aurovrata Avatar answered Nov 16 '22 00:11

Aurovrata


If you are using wordpress custom post type, then you can get required info by following funcitons:

  1. Custom post type label

    $post_type = get_post_type_object( get_post_type($post) ); $post_type->label

  2. Custom field title

    $field_name = "ice_cream"; //slug of custom field "Ice Cream" $field = get_field_object($field_name);

so you can use them in your breadcrumb as: $post_type->label / $field['label']

like image 35
prashant Avatar answered Nov 16 '22 00:11

prashant