WP-API Multiple Custom Post Custom Fields
-
Sorry if this is an amateur question. I’m a javascript developer.
Right now I have a function that gets the content of the field cta_text for each custom post type of promotions.
How would I iterate through this code to add multiple custom fields? i.e. cta_text, cta_url, etc
add_action('rest_api_init', 'register_post_custom_field'); function register_post_custom_field() { register_api_field( 'promotions', 'cta_text', array( 'get_callback' => 'get_custom_field', 'update_callback' => null, 'schema' => null, ) ); } function get_custom_field( $object, $field_name, $request ) { return get_post_meta( $object[ 'id' ], $field_name, true ); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WP-API Multiple Custom Post Custom Fields’ is closed to new replies.