WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Featured Image
[resolved] Featured image not available by JetPack REST API (3 posts)

  1. sahilsaid
    Member
    Posted 6 months ago #

    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://wordpress.org/plugins/dynamic-featured-image/

  2. Ankit Pokhrel
    Member
    Plugin Author

    Posted 6 months ago #

    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

  3. sahilsaid
    Member
    Posted 6 months ago #

    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' );

Reply

You must log in to post.

About this Plugin

About this Topic