Luke Briedis Luke Briedis - 1 year ago 69
PHP Question

Retrieve wp_terms by category_name

I'm trying to limit the retrieved testimonial (using

) by their category names.
category_name = "xxx" doesn't seem to do anything so I'm at a loss.

function testimonial_shortcode( $atts ) {

$cat = $atts['cat'];

$testim='<div id="owl-demo" class="owl-carousel owl-theme">';
$terms = get_terms( array(
'taxonomy' => 'testimonial',
'category_name' => $cat,
'hide_empty' => true,
) );
foreach($terms as $custom_texonomy){

$imgurl=wp_get_attachment_image_src( $imageid, 'full');

$testim.=' <div class="item">

add_shortcode( 'testimonialcat', 'testimonial_shortcode' );

Answer Source

'category_name' isn't a valid argument for get_terms. The WP reference documentation here lists the acceptable arguments. The one you want is:

'name': (string|array) Optional. Name or array of names to return term(s) for.

So, assuming $cat is the name you want to search for, try changing your get_terms arguments to:

$terms = get_terms( array(
        'taxonomy' => 'testimonial',
        'name' => $cat,
        'hide_empty' => true,
        ) );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download