Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#41253 closed defect (bug) (worksforme)

category meta endpoint always returns an empty array

Reported by: mrg0lden's profile MrG0lden Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: REST API Keywords:
Focuses: rest-api Cc:

Description

As the title says, when I use categories route "/wp/v2/categories/" it returns an array of "category" objects, as stated in the documentation. But it always returns an empty array for meta object, whether it has meta fields or not. However, when I use get_term_meta() I get an associative array that contains all meta fields as key => value pairs -as expected-.

Change History (5)

#1 @dbascent94
9 years ago

Have you made any direct database updates recently? I just encountered this issue and I solved it by resetting the taxonomy cache in the wp_options table. Look for an option_name like ${taxonomy}_children where ${taxonomy} is the hierarchical taxonomy you are trying to query, example: category_children. If you set that back to null, the next time WP runs the query it will recache the results.

#2 follow-up: @rmccue
9 years ago

Is your category meta registered? Meta keys that you want to appear in REST API responses must be registered with the show_in_rest option set to true (or to an array of options).

#3 @rmccue
9 years ago

  • Keywords reporter-feedback added

#4 in reply to: ↑ 2 ; follow-up: @MrG0lden
9 years ago

Replying to rmccue:

Is your category meta registered? Meta keys that you want to appear in REST API responses must be registered with the show_in_rest option set to true (or to an array of options).

Thanks, that works!

#5 in reply to: ↑ 4 @rmccue
9 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Replying to MrG0lden:

Thanks, that works!

Fantastic. :)

Note: See TracTickets for help on using tickets.