php – How do I edit the terms output args or array data?

Question

This correctly prints the terms with images but the wrong order:

<?php $terms = get_the_terms( $post->ID , 'wpsl_store_category' ); 
    foreach ( $terms as $term ) {
    echo '<a href="' .$term_link.'"><img src="' . get_taxonomy_image($term->term_id) . '" alt="'.$term->name.'" class="listing-location-icons" /></a>';
    } 
?>

This correctly prints the terms without images but in the correct order:

<?php
global $post;
$taxonomy = 'wpsl_store_category';

// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );

if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {

    $term_ids = implode( ',' , $post_terms );
    $args = array(
                'taxonomy'    => $taxonomy,
                'include'     => $term_ids,
                //Add more arguments if you need them with a different value from default
            );
    $terms = wp_list_categories($args);

    // display post categories
    echo  $terms;
}
?>

Goal: I would like to have images in the correct order.

How do I combine these or edit the terms in the $args array?

I’m trying to edit the second example to include the first example’s terms: '<a href="' .$term_link.'"><img src="' . get_taxonomy_image($term->term_id) . '" alt="'.$term->name.'" class="listing-location-icons" /></a>'

Thank you

0
Curtis Droppelman 2 months 2021-11-27T00:49:33-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse