Support » Fixing WordPress » Trouble Displaying Custom Post Types

  • I created a custom post type “news” which I want to display on a separate page from my blog.

    I created a functions.php file in my child theme (based on the twentyeleven parent) and so far so good. The new custom post type shows up on my dashboard. I made sure I set both ‘has archive’ and ‘public’ to ‘true’ if that matters.

    But I want to have the list of news items display on a separate page from my blog. So I copied the page.php template over to my child theme. Renamed it, then added a template name (so it would show up in the drop down menu under pages) and added the following line of code before the loop, which I got from researching the internet:

    php query_posts( ‘post_type=news’); ?>

    I created the page to display the list of news items and chose the template I created from the drop down menu. But when I visited the page it show only my blog posts. What am I doing wrong? Thanks

Viewing 1 replies (of 1 total)
  • Try will list any thing posted in your custom post type, just change out your_custom_post_type with news and it should be good.

    $args = new array(‘post_type’ => ‘YOUR_CUSTOM_POST_TYPE’);
    $loop = new WP_QUERY( $args );

    while ( $loop->have_posts()) : $loop->the_post;
    // your loop goes here
    endwhile;

    Please let me know if this doesnt work for you and I would be happy to take a deeper look. This is what I use for my custom post types.

Viewing 1 replies (of 1 total)
  • The topic ‘Trouble Displaying Custom Post Types’ is closed to new replies.