Custom post type archive page for multiple post types

Hi I am working on a archive page which I can use for multiple custom post types. I need to make a variable in the $args array which can change to the post_type name on the basis of
<?php post_type_archive_title(); ?>

So something like this:

Read More
<?php

$post_type = post_type_archive_title();

$args = array(
    'post_type' => $post_type,
    'orderby' => 'title',
    'order' => 'ASC',
    'caller_get_posts' => 1,
    'posts_per_page' => 20,
);

query_posts($args); ?>

But this doesn’t work. Does anyone know how I can fix this?

Related posts

1 comment

  1. From WordPress Codex:

    Function Reference/post type archive title

    This is optimized for archive.php and archive-{posttype}.php template
    files for displaying the title of the post type.

    “Title of post type” is the label, not the post type registered name.

    You can get the registered post type name using get_queried_object(); like this:

    <?php
     $obj = get_queried_object();
     $post_type = $obj->name;
    ?>
    

    I see in your $args array, the caller_get_posts, if you are using WordPress 3.1+, i suggest you to use ignore_sticky_posts that replaced the previous one. Look this ( pagination parameters ).

    Maybe i’m wrong maybe not, if you have any problems, reply here : )

Comments are closed.