• Resolved jboepple

    (@jboepple)


    I know there are a million posts of the same topic, but since everyone’s themes are coded differently, I haven’t been able to find the answer to my problem.

    My theme is listing my categories in alphabetical order because that’s the default. I’ve gone into the editor to see where I can change “name” to “id” but there isn’t any code in there for it.

    I don’t know what to add to make it work. I’ve seen many solutions use the $arg line of code, and I don’t see that anywhere, so maybe that’s the problem.

    Can someone tell me what to add? Thank you ??

    <?php
    			/* translators: used between list items, there is a space after the comma */
    			$categories_list = get_the_category_list( __( '&nbsp; // &nbsp;', 'twentyeleven' ) );
    
    			/* translators: used between list items, there is a space after the comma */
    			$tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
    			if ( '' != $tag_list ) {
    
    			} elseif ( '' != $categories_list ) {
    				$utility_text = __( '<span style="font-family: Crimson Text, serif; font-style: italic; font-size: 16px;" class="entry-utility-prep entry-utility-prep-cat-links">Posted in:&nbsp;</span> %1$s', 'twentyeleven' );
    			}
    
    			printf(
    				$utility_text,
    				$categories_list,
    				$tag_list,
    				esc_url( get_permalink() ),
    				the_title_attribute( 'echo=0' ),
    				get_the_author(),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) )
    			);
    		?>

    `

Viewing 6 replies - 1 through 6 (of 6 total)
  • try to add this filter code to functions.php of your theme:

    add_filter('get_the_categories','get_the_category_sort_by_id');
    
    function get_the_category_sort_by_id( $categories ) {
    
      usort($categories, '_usort_terms_by_ID');
    
      return $categories;
    }

    (not widely tested)

    Thread Starter jboepple

    (@jboepple)

    I put that at the bottom of the functions.php file and I got a Parse Error:

    Parse error: syntax error, unexpected T_FUNCTION, expecting T_STRING or T_VARIABLE or ‘$’ in /var/www/ti/tierslovejoy.com/public_html/wp-content/themes/custom/functions.php on line 616

    Any other suggestions?

    the error is not likely to be caused by the new code;

    check the coding of your functions.php;

    or post the full code of functions.php which is causing the error – please use the pastebin – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code

    Thread Starter jboepple

    (@jboepple)

    thank you alchymyth, this is my first time posting on the codex. I have a friend I usually bug for help but I’m needing help more frequently. Pastebin is awesome.

    Here’s the link to my functions.php code. I’ve placed your suggested code at the bottom of the file.

    https://pastebin.com/V3BnRqDy

    seems that whatever text editor you have used to edit functions.php, has changed the single quotes ' to html entities '

    try to use the dashboard – appearance – editor to add the code:

    add_filter('get_the_categories','get_the_category_sort_by_id');
    function get_the_category_sort_by_id( $categories ) {
      usort($categories, '_usort_terms_by_ID');
      return $categories;
    }
    Thread Starter jboepple

    (@jboepple)

    it worked! thank you so much for your help alchymyth, you’re my hero!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to order my Categories by ID instead of Name’ is closed to new replies.