Can’t retrieve color using rest api ?
-
Hi everyone,
First thanks for this really useful plugin. I have some troubles to get it works – maybe due to me.
I am using WP rest json api and I would like to add a ‘color’ field when requesting categories.
The code doing this is really simple :
function get_category_color( $object, $field_name, $request ) { return get_term_meta($object['id'], ‘cc_color’, true); }
Here,
get_term_meta
exists (checked withfunction_exists
) and$object['id']
is my category id.The table seems also good :
MariaDB [wordpress]> select * from wp_termmeta; +---------+---------+----------+------------+ | meta_id | term_id | meta_key | meta_value | +---------+---------+----------+------------+ | 1 | 5 | cc_color | #e5a629 | | 2 | 3 | cc_color | #ff0245 | | 3 | 2 | cc_color | #FF5B84 | | 4 | 1 | cc_color | #8B80FE | | 5 | 6 | cc_color | #D50184 | | 6 | 4 | cc_color | #850400 | | 7 | 5 | cc_color | #e5a629 | | 8 | 5 | cc_color | #e5a629 | +---------+---------+----------+------------+
But the ‘color’ fields is always an empty string. Of course, I’ve tried to check my setup by returning directly a string and it works great.
I don’t really know what to do (I’m not really use to work with wp).
Thanks a lot !
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Can’t retrieve color using rest api ?’ is closed to new replies.