0

When I execute

'<?php echo get_category_parents(get_query_var('cat'), false, '\' - \''); ?>' 

on the category page bar, which is a sub category of foo, this is the output: 'foo' - 'bar' - ''. How do I remove the last, empty category without PHP functions like explode or substr?

0

How do I remove the last, empty category without PHP functions like explode or substr?

You don't. Look at the source: http://core.trac.wordpress.org/browser/tags/3.6.1/wp-includes/category-template.php#L42 The output you see is intended behavior and there is no filter. My guess is that you are trying to use the function for something it is not meant for.

You could take another approach and use get_ancestors or wp_list_categories but substr or str_replace would be the easiest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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