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.

Code:

print_r($wp->query_vars);
echo "<br><br>".get_query_var('term');
echo "<br><br>".get_query_var('taxonomy');
$term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy') );
echo "<br><br>$term";

Output:

Array ( [titles] => windows-powershell-v2 [taxonomy] => titles [term] => windows-powershell-v2 ) 

windows-powershell-v2

titles

As you can see, the first three lines run fine. The fourth line fails with no error - but it terminates page execution. The specified term does indeed exist in the taxonomy; this is being reached with the URL /titles/windows-powershell-v2/.

Any idea what I'm doing wrong?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

get_term_by() returns object by default. Which should end up in Catchable fatal error: Object of class stdClass could not be converted to string if you try to echo it. Likely you have errors suppressed.

Try var_dump( $term ); instead of echo.

share|improve this answer
    
Yup. Finally figured that out just as you posted. Duh. That could be better-documented, but I wanted $term->name. –  Don Jones Sep 17 '10 at 18:40
    
Most functions that deal with terms return objects, there are simply way more to term than name alone. Run test environment with define('WP_DEBUG', true); makes life much easier when you see errors. –  Rarst Sep 17 '10 at 18:42

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.