0

I'm making a shortcode to return all the terms in this taxonomy. The terms are sorted with krsort by the custom field 'height' made from ACF. I'm following this answer from here.

The problem is it's only displaying 8 terms and there's 15 in total. All of these terms have the custom field filled out and have posts for them so I'm not sure.

I need this object array because I will be displaying other parameters in foreach.

function taxonomies_shortcode( $atts ) {
    extract( shortcode_atts( 
        array(
            'taxonomy' => 'taxonomy',
        ), $atts 
    ));
    $args = array( 
        'taxonomy' => $taxonomy,
    );
    $terms = get_terms( $args );
    $newterms = array(); 
    foreach($terms as $term) {
        $order = get_field( 'height', $term );                
        $newterms[$order] = (object) array(
            'name' => $term->name,
            'slug' => $term->slug,
            'term_id' => $term->term_id
        );
    }
    ksort( $newterms, SORT_NUMERIC );
    foreach ( $newterms as $newterm ) {     
        $html .= '<a href="#' . $newterm->slug . '">' . $newterm->name . '</a>';
    }
    return $html;
}
add_shortcode( 'taxonomies', 'taxonomies_shortcode' );

Would appreciate any help, thanks!

1 Answer 1

1

If you are missing terms, maybe try to show all terms, event those that are not assigned to a post. By default, wordpress does not get terms that are not in a post.

get_terms($taxonomy, array('hide_empty' => false));
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.