WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Advanced Custom Field]Update the attachment's post_parent of type Image (2 posts)

  1. ringomamama
    Member
    Posted 1 year ago #

    Would like to ask which is the most suitable hooks to do this?
    something like:

    function my_acf_update_value( $value, $post_id, $field  )
    {
        wp_update_attachment_metadata( $value, array('post_parent'=>$post_id) );
        return $value;
    }
    
    add_filter('acf/update_value/type=image', 'my_acf_load_field', 10, 3);

    Thanks for any helps, gratitude!

  2. ringomamama
    Member
    Posted 1 year ago #

    always figure out the solution right after posted the question, the solution is here:

    function my_acf_update_value( $value, $post_id, $field  )
    {
    	wp_update_post(array(
            'ID' => $value,
            'post_parent' => $post_id
        )
    	);
        return $value;
    }
    
    // acf/update_value/type=image - filter for a specific field based on it's type
    add_filter('acf/update_value/type=image', 'my_acf_update_value', 10, 3);

Topic Closed

This topic has been closed to new replies.

About this Topic