WordPress Menu for current Custom Post Type

I am looking to automatically create a WordPress Menu for the ‘current’ Custom Post Type. I found a useful snippet that outputs the current custom post type here:-

 $post_type = get_post_type( $post->ID );
 echo $post_type;

But am struggling to translate this (or alternate method) into a dynamically created menu for the current custom post type – list all posts in the custom post type. I can’t do this on an individual custom post type basis as I’m using a master template to display a series of custom post types.

Read More

Thanks

Glennyboy

Related posts

Leave a Reply

1 comment

  1. Here’s a super simple way to do it. just create a loop that lists all the page titles wrapped in a link.

    <?php 
        $obj = get_post_type_object(get_post_type($post->ID));
        echo '<h2>' .  $obj->labels->name . '</h2>';
    ?>
    <ul>
        <?php 
            $query = new WP_Query(array('post_type' => get_post_type($post->ID), 'posts_per_page' => -1, 'order' => 'DESC', 'orderby' => 'date',));
            while ( $query->have_posts() ) : $query->the_post();    
        ?>
    
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>  
    
        <?php endwhile; wp_reset_postdata(); ?>
    </ul>
    

    This will loop through all the current post’s post type and create an unordered list with all the posts titles, wrapped in links to the posts. You could obviously change the HTML to suit your needs.