WordPress.org

Support

Support » Plugins and Hacks » Default category?

Default category?

  • 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!

    http://wordpress.org/extend/plugins/taxonomy-terms-order/

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default category?’ is closed to new replies.