Support

Account

Home Forums Backend Issues (wp-admin) Set image as featured image

Solved

Set image as featured image

  • Thanks @squarecandy, but if I’ve got an existing image field and I replace the name field from my field group, all my old images go away.
    How can I keep them if I change the field name?

    Thanks in advance!

  • Hmm, yeah. Much harder if you already have a field name with data that you need to preserve. See this thread: https://support.advancedcustomfields.com/forums/topic/changing-field-name-question/

  • Thanks for your reply @squarecandy, I’ll take a look.

  • here my actual code with that i publish posts form an external form ( using ACF ) :

    function generate_post_from_form_submission() {

    // Get the submitted field values
    $post_title = af_get_field( ‘titolo’ );
    $post_content = af_get_field( ‘contenuto’ );

    // Set up a form using the values for post title and content
    // Replace post_type with whatever type of post you want to generate
    $post_data = array(
    ‘post_type’ => ‘libri’,
    ‘post_status’ => ‘publish’,
    ‘post_title’ => $post_title,
    ‘post_content’ => $post_content,
    );

    // Create post with the previously retrieved values
    $post_id = wp_insert_post( $post_data );

    // Save extra_information field directly to custom field on post
    af_save_field( ‘titolo’, $post_id );
    af_save_field( ‘contenuto’, $post_id );
    af_save_field( ‘copertina’, $post_id );
    af_save_field( ‘immagine’, $post_id );
    af_save_field( ‘autore’, $post_id );
    af_save_field( ‘editore’, $post_id );
    af_save_field( ‘codice’, $post_id );
    af_save_field( ‘punto_di_ritiro’, $post_id );
    af_save_field( ‘citta’, $post_id );
    af_save_field( ‘galleria’, $post_id );

    }
    add_action( ‘af/form/submission/key=form_********’, ‘generate_post_from_form_submission’, 10 );

    How can i solve to can have the field “immagine” to insert a featured image?
    I’ve seen your code :

    <?php

    function acf_set_featured_image( $value, $post_id, $field ){

    if($value != ”){
    //Add the value which is the image ID to the _thumbnail_id meta data for the current post
    add_post_meta($post_id, ‘_thumbnail_id’, $value);
    }

    return $value;
    }

    // acf/update_value/name={$field_name} – filter for a specific field based on it’s name
    add_filter(‘acf/update_value/name=cursusfoto’, ‘acf_set_featured_image’, 10, 3);

    ?>

    and ‘ve understood that it must be placed on functions.php ( where there is my code above ) but has not worked so i’m here to ask help .

    Thank You

  • Its possible to make a conditional for multiple featured images based on a select option acf??

Viewing 5 posts - 51 through 55 (of 55 total)

The topic ‘Set image as featured image’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.