PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, April 11, 2022

[FIXED] order post taxonomies alphabeticaly in wordpress?

 April 11, 2022     custom-tags, taxonomy, taxonomy-terms, wordpress     No comments   

Issue

I'm using a custom taxonomy for my posts which I print like this:

the_terms(get_the_ID(), 'sizes', '<p>', ', ', '</p>');

This works fine but it prints the terms in the order they were added, is there a way to make it print alphabeticaly? the_terms function doesn't let me pass any order parameter so I guess I have to use a different one but I haven't found any yet.

Thanks in advance.


Solution

the_terms() is using get_term_list, to retrive the taxonomy ( http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/category-template.php#L932 ) for the code.

You have the option to use a filter here, but it is applyed to the HTML generated for every single term (taxonomy1). Not the best option to sort.

Best is use the function get_the_terms() , sorting the results and constructing the output list by yourself!



Answered By - keatch
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing