Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #2781744
REST API
Closed

Comments

  •  1
    waerp started the conversation

    Hi,

    is it possible to extend the existing WP REST API with the fields from recipes? This would be awesome. 

    I am trying to create an app for my recipe homepage and just want to show there also recipes.

    Best regards

  •  2,616
    PenciDesign replied

    Hi,

    Please install the Code Snippet plugin, then add the following code:

    function waerp_filter_post_json( $data, $post, $context ) {
        $postmetas = get_post_meta($post->ID);
        foreach($postmetas as $meta_key=>$meta_value) {
            $data->data[$meta_key] = $meta_value[0];
        }
        return $data;
    }
    add_filter( 'rest_prepare_post', 'waerp_filter_post_json', 10, 3 );

    This code will return all custom meta keys of post type name: post in REST API result.

    Best Regards,
    PenciDesign.