WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Matt Hill
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

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

  3. Matt Hill
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    I should have use the word posts, or items.

    <?php
    $args=array(
      '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>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  5. Matt Hill
    Member
    Posted 4 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:

    http://www.mysite.com/blog/title-of-post-in-blog-cat/
    http://www.mysite.com/news/title-of-post-in-news-cat/

    Many thanks for any insights :-)

  6. MichaelH
    Member
    Posted 4 years ago #

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

  7. Matt Hill
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    One or more Mailing Lists.

  11. hixen
    Member
    Posted 3 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.

    http://bajada.net/2010/07/15/adding-custom-post-types-to-wp_get_archives

Topic Closed

This topic has been closed to new replies.

About this Topic