• Hi,
    I want to report about an issue I am facing using WP API.
    I have lots of Categories and Child Categories Hierarchy.
    At the Post Endpoint of the REST API, the Category and Child Category IDs are not always maintained term_order or any order to be precise. By default, it should follow the parent-child order.
    Some posts show it correctly but some of the posts are in the incorrect order.

    If my WordPress categories are in the following order:

    Category 1 (ID 1)
     -Category 4 (ID 4)
     -Category 5 (ID 5)
     -Category 6 (ID 6)
    Category 2 (ID 2)
     -Category 7 (ID 7)
     -Category 8 (ID 8)
     --Category 9 (ID 9)
     --Category 10 (ID 10)
    Category 3 (ID 3)
     -Category 11 (ID 11)
     -Category 12 (ID 12)

    I query /posts?categories=10 where posts are also marked under Category 2, Category 8.
    The result should be like – [2,8,10]
    But instead, it shows like – [8,2,10] or [2,10,8] etc

    Why I am facing this issue? Any one else face this issue?

    • This topic was modified 4 years, 5 months ago by arindam4u.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’ve observed the same behavior. I never considered it an “issue”. WP makes no effort to order the category IDs returned with a post. I never expected it to. TBH, I’m not sure where term_order is really used, but it’s not used when querying posts through the API.

    If you need data in a specific order, the code receiving the response would need to manage that itself.

Viewing 1 replies (of 1 total)
  • The topic ‘WP API Post Categories not in term_order in Posts Endpoint’ is closed to new replies.