• Resolved sahilsaid

    (@sahilsaid)


    Hi,

    Thanks for this plugin.

    I have a problem fetching the URL of the featured images with JetPack REST API.

    The REST API only recognises the image if new image was uploaded and set as featured image.

    If I choose the dynamic featured image from Media Library then they are not listed in the json returned from request.

    To confirm this is the exact problem I set around four featured images for my custom post. I now set two of these featured images by uploading fresh ones and two from Media Library. Now returned JSON only recognizes former two and ignores latter.

    Do you have any easy fix for this?

    Thanks.

    https://www.ads-software.com/plugins/dynamic-featured-image/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hello sahilsaid,

    Thank you for trying the plugin.

    I haven’t tried to fetch the plugin contents using JetPack REST API. I don’t think i have any quick fix for this but can you please try the new version from here https://github.com/ankitpokhrel/Dynamic-Featured-Image (master branch)? This version is not yet live but it is working. It uses new media library “Set featured image” functionality to set the featured image. This might solve your problem.

    Also the plugin contents are saved in ‘postsmeta’ table and it has nothing to do with WordPress default featured image functionality. I think that the plugin values should show up somewhere in meta values returned by the Jetpack Rest API.

    Thanks,
    Ankit

    Thread Starter sahilsaid

    (@sahilsaid)

    I have fixed this problem by adding the dynamic featured image meta key into allowed types for JSON API with the filter ‘rest_api_allowed_public_metadata’. I used the code below.

    function custom_rest_api_allowed_public_metadata( $allowed_meta_keys )
    {
        // only run for REST API requests
        if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST )
            return $allowed_meta_keys;
    
        $allowed_meta_keys[] = 'dfiFeatured';
    
        return $allowed_meta_keys;
    }
    
    add_filter( 'rest_api_allowed_public_metadata', 'custom_rest_api_allowed_public_metadata' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured image not available by JetPack REST API’ is closed to new replies.