Get list of registered custom post types

Your code looks good. However, you can try the followoing codes to get all custom posts

    $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>';
    }

    ?>

you can also use a bunch of args to filter your result much. For details lists of args you can check the official WordPress Codex page: https://codex.wordpress.org/Function_Reference/get_post_types

Leave a Comment

error code: 523