I created custom end points for my custom post types to get only data that I want like title, content and featured image and few custom fields. I am getting REST json data fine.

I am building an app and I want users to submit the data from app to that particular post type and not all content.

Means I want POST method for my one custom post type and others should remain untouched that means only GET method.

Here is my code for custom rest api endpoint --

function mycustomendpoint() {
    $args = [
        'numberposts' => 99999,
        'post_type' => 'mycustompostype'

    $posts = get_posts($args);

    $data = [];
    $i = 0;

    foreach($posts as $post) {
        $data[$i]['id'] = $post->ID;
        $data[$i]['DonorName'] = $post->post_title;
        $data[$i]['DonorCity'] = $post->donor_city;
        $data[$i]['DonorMobile'] = $post->donor_mobile;
        $data[$i]['DonorBloodGroup'] = $post->blood_group;
        $data[$i]['DonorLink'] = get_the_permalink($post->ID);
        $data[$i]['Slug'] = $post->post_name;
        $data[$i]['DonorPhoto']['thumbnail'] = get_the_post_thumbnail_url($post->ID, 'thumbnail');
        $data[$i]['DonorPhoto']['medium'] = get_the_post_thumbnail_url($post->ID, 'medium');
        $data[$i]['DonorPhoto']['large'] = get_the_post_thumbnail_url($post->ID, 'large');

    return $data;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.