• Resolved kokoruz

    (@kokoruz)


    Getting terms from some users inexplicably do not show up. I cannot figure out why. I am using the get terms samples below and while this works for the majority of my users I have user accounts with terms assign to them that have absolutely nothing show up. I have even changed $user->ID to the users actual id number and still nothing. I have gone in the database and have confirmed the terms are being recorded and the relationships between the object_id and the term_taxonomy_id exist in the term relationships. In two specific cases my object_id is 8 and 34. I can take the below script, paste it on any page, replace $user->ID with 34 and zero terms are returned. I’d really love some feedback as I am truly perplexed.

    echo get_the_term_list( $user->ID, 'service', '<p><span class="label">Services:</span><span class="data">', ', ', '</span></p>' );
    or

    $terms = get_the_terms(  $user->ID, 'service' );
        if( ! empty( $terms ) ) :
            foreach( $terms as $term ) : ?>
            <div class="<?php echo $term->slug; ?>"><?php echo $term->description; ?></div
    <?php endforeach;
        endif;
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author shawfactor

    (@shawfactor)

    Really hard to diagnose, can I confirm that the service taxonomy you created is for users only.

    Can you try https://codex.www.ads-software.com/Function_Reference/wp_get_object_terms

    eg

    $terms = wp_get_object_terms( $user->ID, ‘service’ );

    print_r($terms);

    It is a lot safer than get_the_terms which is really just for posts

    Thread Starter kokoruz

    (@kokoruz)

    Thanks for the update. Not sure I can explain why but Monday when I got back to work on this everything seemed to be working correctly but I appreciate the response and the wp_get_object_terms code.

    Thread Starter kokoruz

    (@kokoruz)

    I have adjust me code. Everything looks like it is working well.

    $service_terms = wp_get_object_terms(  $user->ID, 'service' );
    if ( ! empty( $service_terms ) ) {
        echo '<p><span class="label">Services:</span><span class="data">';
    	if ( ! is_wp_error( $service_terms ) ) {
    		echo '<ul>';
    			foreach( $service_terms as $service_term ) {
    				echo '<li><a href="' . get_term_link( $service_term->slug, 'service' ) . '">' . esc_html( $service_term->name ) . '</a></li>'; 
    			}
    		echo '</ul>';
    	}
    }

    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Terms Not Consistent’ is closed to new replies.