WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have custom post type called staff that has custom taxonomy called departments. I wanted the frontpage of the staff (archive-staff.php) to not show ALL the staff members, but actually the first department (lets say there are 3 departments.)

My archive page starts like this:

global $wp_query;
$args = array_merge( $wp_query->query, array(
    'post_type' => 'staff',
) );
query_posts( $args );

while (have_posts()): the_post(); // ...

I have no clue how to go from here. I also need to display the current departments title.

share|improve this question
$tax_slug = 'departments';
$tax_term = 'first-department';
// get taxonomy by slug and term
$tax_args = array( $tax_slug => $tax_term );
// merge your args, with the tax args
$args = array_merge( $args, $tax_args );

// Get term object
$term_title = get_term_by( $tax_term, '', $tax_slug );

// Display Title/Headline
echo "<h2>{$term_title->name}</h2>";
share|improve this answer
@t31os Why? $tax_slug is the key for tax querie args. – kaiser Dec 12 '11 at 18:58
Sorry, read too quick, then really the fix should have been an $ (missing) and not quotes.. my mistake.. – t31os Dec 12 '11 at 19:19
Thank you for answering, however this didn't work for me at all. The comments didn't explain or refocus as much as needed and there was no additional information in your post :( – Kalle H. Väravas Dec 18 '11 at 22:20
What "post"? Btw: You need to store your $args first. Else you can't array_merge them... Thas why I've written // merge YOUR args, with the tax args – kaiser Dec 18 '11 at 22:28
up vote 0 down vote accepted

This is what worked for me:

// Custom taxonomy
$custom_taxonomy = 'department';

// Get the current department
if (!$current_department = $wp_query->query_vars[$custom_taxonomy]) {
    $get_all_departments = get_terms($custom_taxonomy, array(
        'number' => 1
    $current_department = $get_all_departments[0]->slug;

// Get the departments information
$department = get_term_by('slug', $current_department, $custom_taxonomy);

So the $current_department is the slug of the current taxonomy and $department is an array of the current taxonomy.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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