Category Order and Taxonomy Terms Order
Default category? (3 posts)

  1. benkamin
    Posted 3 years ago #

    AutoSort is on,
    My posts have multiple categories,
    But when I call get_category() I still get the fist category alphabetically and not by the order I used this plugin to order the categories.

    I want to use this plugin to define categories priority, so when I'm displaying only one category of a post, I will have control which category it is.

    Can this be done with this plugin?

    Many thanks!


  2. Steven Jones
    Posted 3 years ago #

    I don't think the plugin is meant for this. The best way I can think of doing it is to:

    a) Get all of the names of the categories

    get_terms('category', 'fields=names');

    b) get_terms returns object so you'll need to put them into an array

    $array1 = array("news", "sport", "fashion", "weather");

    c) Get the list (returns an array) of categories attached to the post

    $array2= wp_get_post_terms($post->ID, 'category', array("fields" => "names"));

    d) Loop through array1 (which is in your order) and check if the first item appears in the array2 (in_array). When you find the first one then you can print it out and quit the process.

    Hope that gets you started.

  3. benkamin
    Posted 3 years ago #

    Looks very interesting Steven, thanks!
    But can anybody think of a simpler way, maybe using this or another plugin?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Category Order and Taxonomy Terms Order
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.