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 ars technica

  • OpenAI feels “burned” by Apple’s crappy ChatGPT integration, insiders say
  • Desperate Trump taps "Tim Apple," Jensen Huang, Elon Musk to attend Xi summit
  • Court rules Trump's 10% tariff is just as illegal as the tariff it replaced
  • Which Macs are suffering from shortages—and where are things getting worse?
  • Mac mini starting price goes up to $799, may be hard to get for "months"

RSS mac surfer

  • Apple Registers GenAI Subdomain Ahead of WWDC
  • Ben Stiller, Mike Judge Team for Apple TV Comedy
  • Apple Asks Supreme Court to Review Epic Contempt Ruling
  • Apple TV to Broadcast MLS Game on iPhone 17 Pro
  • OLED MacBook Pro Display Production Back on Track

Donate

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

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