I need to set an image as featured in WordPress via ajax call. So i did this function:

   function FeaturedImage() {
    $image_ID = $_POST['thumbnail_id'];
    $post_ID =  $_POST['post_id'];
    check_ajax_referer( 'savemediaimage', 'nonce' );
    update_post_meta( $post_ID, '_thumbnail_id', $image_ID );
    add_action( 'wp_ajax_postthumbnail',        'FeaturedImage' );
    add_action( 'wp_ajax_nopriv_postthumbnail', 'FeaturedImage'); 

And this is the ajax call:

jQuery.post(ajaxparam.ajax_url, {
    nonce: ajaxparam.nonce,
    post_id : '924',
    thumbnail_id : '887',
    action: 'postthumbnail'

In the console log, post content is:



200 OK

but never image is sets as featured.
I also tried to use set_post_thumbnail instead of update_post_meta without success.
What is wrong? Thanks

Read more here: How to set image as featured via ajax in WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: