0

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:

<?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?

0

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 : )

  • I've tried it with get_queried_obj(); But that gave me the following error: Fatal error: Call to undefined function get_queried_obj() – Robbert Aug 20 '13 at 10:33
  • sorry, sorry! my fault! update the answer – iEmanuele Aug 20 '13 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.