WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 3.7 Displaying custom taxonomy terms by first letter not working. (5 posts)

  1. SpencerCE89
    Member
    Posted 5 months ago #

    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.

  2. vtxyzzy
    Member
    Posted 5 months ago #

    This is a change in WP 3.7 as described under name__like here: http://codex.wordpress.org/Function_Reference/get_terms

    Personally, I think this introduced an unneeded feature since now name__like functions the same as search.

  3. SpencerCE89
    Member
    Posted 5 months ago #

    Is there some way to regain the functionality I lost with that change? Is there another way to get the taxonomy terms to display by the first letter without using the name__like function?

  4. keesiemeijer
    moderator
    Posted 5 months ago #

  5. SpencerCE89
    Member
    Posted 4 months ago #

    That will do for now. Thanks!

Reply

You must log in to post.

About this Topic