Using wordpress template tags within an array

A bit of a noob PHP question coming up.

I am trying to create a generic archive style view for my custom post types. Ideally I want to create one generic template that can be used for all post-types.

Read More

Currently I use this as my have_posts query to bring in all posts of ‘custom-post-type’

<?php
 $args=array(
   'post_type' => 'custom-post-type.',
   '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() ) {
 while ($my_query->have_posts()) : $my_query->the_post(); 
?>

What I want to do is swap out custom-post-type with the slug of the page so that whenever this template is assigned to a page, it will look for a custom-post-type of that name & list them.

Alternatively if you know of a better way of doing it – great!

Cheers,
George

Related posts

Leave a Reply

2 comments

  1. Try this:

    $page = $wp_query->get_queried_object();
    $slug = $page->post_name;
    

    PS I think next WP release will get proper custom post archives or something around that…