Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

$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
add comment
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
add comment

Your Answer

 
discard

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.