Ranjit
Ranjit

Reputation: 1724

To get the custom type post "name" and "label" only

I am using the code below to get the post name and post label. But I don't want all the custom types like "post", "page" and "attachment." I need the custom post types "name" and "label" only.

  $types = get_post_types( array( 'exclude_from_search' => false ), 'objects' ); ?>

          <?php foreach ( $types as $type )
            {
              echo '<li>' . $type->name . '</li>';
              echo '<li>' . $type->singular_label . '</li>';
              }
          ?>

How can I get the custom post type "name" and "label" only?

Upvotes: 0

Views: 738

Answers (1)

stealthyninja
stealthyninja

Reputation: 10371

Add

'public'   => true,
'_builtin' => false

to your arguments like so:

$types = get_post_types( array( 'exclude_from_search' => false, 'public' => true, '_builtin' => false ), 'objects' );

This should then only display your custom post type(s).

Upvotes: 1

Related Questions