0

i created a custom post type called 30 day boot camp using this code:

add_action( 'init', 'rt_custom_post' );
function rt_custom_post() {
  register_post_type( '30-day-boot-camp',
    array(
    'labels' => array(
        'name' => __( 'Boot Camps' ),
        'singular_name' => __( 'Boot Camp' ),
        'add_new' => _x('Add New', 'Boot Camp'),
        'add_new_item' => __("Add New Boot Camp"),
        'edit_item' => __("Edit Boot Camp"),
        'new_item' => __("New Boot Camp"),
        'view_item' => __("View Boot Camp"),
        'search_items' => __("Search in Boot Camps"),
        'not_found' =>  __('No Boot Camp'),
        'not_found_in_trash' => __('No Boot Camp found in Trash')

      ),
    'public' => true,
    'has_archive' => true,
       'menu_icon'   => 'dashicons-calendar-alt',
    'supports' => array('title','editor','thumbnail','author'),
    )
  );
}

When i am on the archive page (archive-30-day-boot-camp.php) i can pull the name for the boot camp by this code:

<?php if ( is_post_type_archive( '30-day-boot-camp' ) ) : ?>
<h1 class="h-landmark entry-title"><span>
<?php post_type_archive_title(); ?></span></h1>
<?php endif?>

and it returns "boot camps"

However when i go to a single entry on my (single-30-day-boot-camp.php) i can't understand how to return the custom post type name. I want it to return "boot camps" Not just the post title itself. (which could for instance be "day 1".)

i tried:

<?php post_type_archive_title(''); ?>

but nothing shows up

i also tried

<?php post_type_archive_title('30-day-boot-camp'); ?>
1

If you're within the loop then the_title() should return the post type's title. post_type_archive_title is specifically for archives.

To get the human readable name of the post type, though, I've not seen anything better than this from the Codex:

$obj = get_post_type_object( '30-day-boot-camp' );
echo $obj->labels->singular_name;
2
  • i don't want to return the title of the post itself i want to return the title of the post type.. So it would say "boot camps" at the top of the single page and then a little lower i'll return post title. Sorry if i wasn't clear.
    – rudtek
    Jun 10 '16 at 20:39
  • Ah. I've updated my answer accordingly. Jun 10 '16 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.