1

Is there a function to list all custom post types in a metabox?

I have

wp_list_pages( $args );

to list the pages in metabox but now I need also to list all custom post types.

Thanks for advices

1 Answer 1

2
<?php

   $args = array(
  'public'   => true,
    '_builtin' => false
 );

 $output = 'names'; // names or objects, note names is the default
  $operator = 'and'; // 'and' or 'or'

 $post_types = get_post_types( $args, $output, $operator ); 

 foreach ( $post_types  as $post_type ) {

     echo '<p>' . $post_type . '</p>';
 }

?>

It will list of all public custom post types and you can read documentation on get_post_types here .

2
  • 1
    Would be nice if you can link to the get_post_types (which is used here) codex page and briefly explain how the code works :-) Sep 15, 2014 at 7:30
  • Glad it worked for you ! Enjoy coding :) Sep 15, 2014 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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