0

I am trying to format a template page for a custom taxonomy and I'm having a hard time getting the term of the current page to use in the query. This is what I've tried so far:

<?php       
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $report = single_term_title();
        $report_type = strtolower($report);
        $temp = $wp_query; 
        $wp_query = null; 
        $args = array(
          'showposts'=> 5,
          'orderby'  => 'meta_value',
          'meta_key' => 'report_date',
          'order' => 'DESC',        
          'post_type'=> 'match_report',
          'report_type' => $report_type,
          'paged'    => $paged
        );
        $wp_query = new WP_Query(); 

        $wp_query->query($args);            
        if ( $wp_query->have_posts() ) :
        ?> 

when I echo $report_type I still get an uppercase value. Is there another function that I should be using rather than single_term_title()?

1
  • 1
    showposts is deprecated use posts_per_pageinstead
    – JMau
    Commented Jul 11, 2013 at 13:26

1 Answer 1

1

Do what single_term_title does and check the queried object with get_queried_object.

function single_tax_slug() {
  $term = get_queried_object();

  if ( !$term )
    return;

  if ( is_category() ) {
    $term_slug = $term->slug;
  } elseif ( is_tag() ) {
    $term_slug = $term->slug;
  } elseif ( is_tax() ) {
    $term_slug = $term->slug;
  }

  return $term_slug;
}
$slug = single_tax_slug();
var_dump($slug);

If you look at that code, it is basically the first few lines of single_term_title, simplified considerably, and altered to get the slug.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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