Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

List all WordPress Custom Post Types in a Menu

October 10, 2014 Leave a Comment

cpt-wordpress-listWant to display a list of a certain WordPress Custom Post Types in a list or menu? You can do this with a simple query using WP Query.

WP Query is the preferred function to query all posts in WordPress and has a multitude of arguments and parameters that can be passed in to change the output.

<?php

// Define the WP query
$args = array(
    'post_type' => 'custom-post-type-name',//Swap in your CPT
    'posts_per_page' => -1,
);

$query = new WP_Query( $args );

if ($query->have_posts()) {
     
    // Output the post titles in a list
    echo '<ul id="cpt-menu">';
     
        // Start the Loop
        while ( $query->have_posts() ) : $query->the_post(); ?>
 
        <li class="cpt-menu-item" id="post-<?php the_ID(); ?>">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
         
        <?php endwhile;
         
        echo '</ul>';       
}
     
// Reset the WP Query
wp_reset_postdata();

?>

In the arguments $args add your defined Custom Post Type name to ‘post_type’. To display all the posts set ‘posts_per_page’ to -1. To see more extensive arguments, they are all listed in the Codex.

You can add in CSS classes to the HTML, defining both the list and list item elements. The code is set to output the post title only which is wrapped in the permalink of that post. If you need to output this in a widget just ensure you have allowed PHP to run in the widgets.

Cats: WordPress

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Discuss

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls
Get DesktopServer

Lynda

Lynda.com Online Training Videos

TreeHouse

smlinks

Learn WordPress
osx-modify-shell-path

How to Add to the Shell Path in macOS Big Sur and Catalina using Terminal

October 19, 2019

virtual-hosts osx 10.10 yosemite

Set up Virtual Hosts on macOS Catalina 10.15 in Apache

October 19, 2019

Installing Homebrew on macOS Catalina 10.15, Package Manager for Linux Apps

October 18, 2019

Where is the bash shell in macos Catalina?

October 12, 2019

Refine your search

  • All
  • Modules
  • Themes
  • Documentation
  • Forums & Issues
  • Groups

RSS feed: ars technica ars technica

  • It's a weird time to buy a laptop, but the new MacBook Pro doesn't skimp on quality
  • 2026 iPad mini review: Maximizing the mini
  • Coming in 2027: Apple’s $1,000 home robot for FaceTime and switching on lights
  • Touchscreen MacBook Pro hands-on: OLED looks great on a Mac
  • Apple announces touchscreen MacBook Pro with OLED display

RSS feed: mac surfer mac surfer

  • Apple Invites Gains Guest Polls and Emoji Effects
  • Google Gemini Launches on Apple CarPlay
  • iPhone Duo Draws Mixed Reactions From Early Buyers
  • Apple Meets Thai Officials Over Mercenary Spyware Alerts
  • Apple Support Community Forums Close November 20

Donate

Copyright © 2026· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2026 · gee on Genesis Framework · WordPress · Log in