• Resolved SpencerCE89

    (@spencerce89)


    I use the following code to display the terms in one of my custom taxonomies by the first letter:

    <div class="charactericon">
     <?php
    $letter = 'A';
    
    $paged_terms = false;
    
    // current page number
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    // get posts per page as set in the reading settings
    $posts_per_page = get_option( 'posts_per_page' );
    
    // get all terms starting with the letter
    $terms = get_terms( "character", array( 'name__like' => $letter ) );
    
    // check if terms where found
    if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
    
    	// get paged terms
    	$paged_terms = array_slice( $terms, ( $paged-1 ) * $posts_per_page, $posts_per_page );
    	if ( $paged_terms ) {
    
    		// display terms
    		echo "<ul>";
    		foreach ( $paged_terms as $term ) {
    			echo '<li><div class="spacer"></div><a href="' . get_term_link( $term ) . '">'. $term->name . '</a> <a href="' . get_term_link( $term ) . '"><img src="/characterprofile/characterthumbs/A/'.$term->slug.'".jpg/></a></li>';
    		}
    		echo "</ul>";
    
    		// clear
    		echo '<div class="clear">';
    		echo '</div>';
    
    		// create a fake query for pagination functions
    		$fake_query = new WP_Query;
    		$fake_query->max_num_pages = ceil( count( $terms ) / $posts_per_page );
    
    		// display pagination
            echo '<div class="paginator">';
            if ( function_exists( "pagination" ) ) {
    	    pagination( $fake_query->max_num_pages );
            }
            echo '</div>';
    
    	}
    }
    
    if ( !$paged_terms ) {
    	_e( 'Sorry, no terms where found.' );
    }
    ?>
    
      </div>

    Now, instead of showing each term that -begins- with that letter, it’s showing every term that -includes- that letter.

    So for example, for the letter “A”, it will show “Admiral Ackbar” as well as “Princess Leia”, since both contain the letter “A”, instead of just showing “Admiral Ackbar”, which begins with “A”

    I’m pretty sure this happened when I updated to 3.7. No other changes had been made which would have caused this, as far as I can tell.

    Any help would be greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘3.7 Displaying custom taxonomy terms by first letter not working.’ is closed to new replies.