Support » Fixing WordPress » How to display all posts of a custom post type?

  • Resolved Julian245



    how can I display all posts of a custom post type on a page?

    I hope you can help me.



Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael


    Forum Moderator

    create a page template
    add a loop
    with a custom query
    using the ‘post_type’ parameter in the query

    you might want to start the code of the page template with a copy of index.php or page.php of your theme…


    I did what the Codex said, but it’s still not working. If i go to (my archive page) The title says ‘Page not found’.

    Maybe I made a mistake in my codes:


     Template Name: Music
     get_header(); ?>
    <div class='eleven columns'>
    		$my_query = new WP_Query( "cat=3" );
    			if ( $my_query->have_posts() ) {
    				while ( $my_query->have_posts() ) {
    <div class='four columns offset-by-one'>
    	<?php get_sidebar('right-sidebar'); ?>
    <?php get_footer(); ?>

    Music.php (to register the post type)

    function elex_posttype_music() {
    	$labels = array(
    		'name' => 'Music',
    		'singular_name' => 'Music',
    		'add_new' => 'Add Track',
    		'add_new_item' => 'Add New Track',
    		'edit_item' => 'Edit Track',
    		'new_item' => 'New Track',
    		'view_item' => 'View Track',
    		'search_items'=> 'Search Tracks',
    		'not_found' => 'No Tracks Are Found',
    		'not_found_in_trash'=> 'No Tracks Are Found In Trash',
    		'view' => 'View Track'
    	$args = array (
    		'labels'=> $labels,
    		'description' => 'This is the holding location for your tracks',
    		'public'=> true,
    		'has_archive' => true,
    		'exclude_from_search'=> false,
    		'show_ui' => true,
    		'rewrite'=> true,
    		'hierarchical' => true,
    		'menu_position'=> 5,
    		'supports' => array('thumbnail', 'title', 'editor')
    add_action('init', 'elex_posttype_music')

    include_once(TEMPLATEPATH . '/inc/posttypes/music.php');



    Forum Moderator

    your query does not contain the parameter for 'post_type';


    $my_query = new WP_Query( "cat=3&post_type=Music" );

    do you need the cat parameter?

    Oh no, the cat par was a mistake.

    I edited my code, but it’s still not working…

    I could share my project if you want?

    Its working, problem solved 😉

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display all posts of a custom post type?’ is closed to new replies.