How to get functions like wp_get_archives to work with Custom Post Types? (11 posts)

  1. Matt Hill
    Posted 5 years ago #

    I can't seem to use functions like wp_get_archives with Custom Post Types. These functions still return all the posts associated with the main blog posts.

    Is there any way of filtering out the Custom Post Types for functions like these?

    My issue is that I have both a blog and a news section. The blog uses all the standard templates and functions, but my News section is done with Custom Post Types. However, I still want to use all the standard blog features in the News section too.

    Is this possible?

  2. MichaelH
    Posted 5 years ago #

    Not really--you can use a Page Template and display the object in that post type though.

  3. Matt Hill
    Posted 5 years ago #

    Hi, thanks for the reply. "Display the object in that post type" -- not entirely sure what you mean by this? What object?

  4. MichaelH
    Posted 5 years ago #

    I should have use the word posts, or items.

      'post_type' => 'news',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of News Items';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    wp_reset_query();  // Restore global post data stomped by the_post().
  5. Matt Hill
    Posted 5 years ago #

    Ah, right, thanks. Yes, I thought about this but still wanted to use some of the built in stuff like displaying them in dated archives.

    What I'm trying to do is to have something like this:

    http://www.mysite.com/blog/ <- display using standard WP blog stuff
    http://www.mysite.com/news/ <- custom post types

    For the News option, I'd ideally like to still filter them and manage them using all the standard WP functions.

    I thought about doing them as category slugs instead and setting 'Blog' and 'News' categories and not using custom post types for News. But to do this, I'd need to set the custom permalinks to "%category%" which I've read is a bad idea.

    Do you have any views on this, or suggestions for other ways I can accomplish this and still retain the correct child URLs for the different areas? Eg:


    Many thanks for any insights :-)

  6. MichaelH
    Posted 5 years ago #

    I think you'll see more of that stuff in 3.1 or later.

  7. Matt Hill
    Posted 5 years ago #

    I hope so. It does seem a strange design decision to exclude custom post types from working with many of the core WP functions. I realise that's a big job, but it does seem strange to bring out such a great feature that's already half crippled from the start.

    One might have assumed that people will want to use all the standard WP functions with Custom Post Types and I think a lot of people are going to be disappointed when they discover that they can't. It seems a bit of a missed opportunity. :-(

  8. MichaelH
    Posted 5 years ago #

    Yeah it's going to be interesting to hear the clamor about that with 3.0. Part of the reason Otto at ottopress.com says you better have a darn good reason for using custom post types ;)

  9. Matt Hill
    Posted 5 years ago #

    I dip in and out of following WordPress development: I'm a bit out of the loop at the moment. Is there a good place to follow discussions on future developments of Custom Post Types? Cheers.

  10. MichaelH
    Posted 5 years ago #

    One or more Mailing Lists.

  11. hixen
    Posted 5 years ago #

    Don't know if this was what you where looking for, but it worked for me, and I think I had the same problem as you.


Topic Closed

This topic has been closed to new replies.

About this Topic