Changer des données d’un article en fonction de champs ACF (titre, image)

Image mise en avant via champs ACF

Les articles nourris par ACF n’ont nativement pas d’image mise en avant.
Ces lignes de code permettent d’attribuer comme Featured Image un champs ACF particulier
(ici : ‘image_spectacle’ est le nom du champs ACF)

https://www.softaox.info/advanced-custom-fields-set-image-field-as-post-featured-image/

/**
 * Plugin Name: Featured Image from ACF field
 * Version: 1.0
 * Description:  The featured image of the post is feed by the ACF Field 'image_spectacle' 
 * Author: Mraj 
 * Author URI: https://www.softaox.info/advanced-custom-fields-set-image-field-as-post-featured-image/
 */
  
add_action('acf/save_post', function ($post_id) {
    $value = get_field('image_spectacle', $post_id);
    if ($value) {
        if (!is_numeric($value)) {
            $value = $value['ID'];
        }
        update_post_meta($post_id, '_thumbnail_id', $value);
    } else {
        delete_post_meta($post_id, '_thumbnail_id');
    }
}, 11);

Le PlugIn :

Titre de l’article donné par champs ACF:

Si on veut que l’article ait son titre dépendant d’un champs particulier, voici un bout de code fort utile:

// ***********Titre du post donné par champs ACF*********************************************
/**
* Generate post title and post slug from ACF single value fields
*
*/

add_action('acf/save_post', 'my_acf_save_post', 5);
function my_acf_save_post( $post_id ) {

    $post_title = 'My default title';
    $slug = 'my-default-slug';

    // Check if a specific field value was updated.
    // Replace field_key with the actual field keys of the fields
    if( isset($_POST['acf']['field_631ef8825133e'])) {
        
        // Replace field_key with keys of the fields needed to generate title
        $post_title = $_POST['acf']['field_631ef8825133e'];
        $slug = sanitize_title( $post_title );
    }

    // Grab Post Data from the Form
    $post = array(
        'ID'           => $post_id,
        'post_title'   => $post_title,
        'post_name'    => $slug,
    );

    // Update the Post
    wp_update_post( $post );
}

Sachant qu’on trouve l’identifiant (key) du champs en cochant la case d’en-tête dans l’administration d’ACF (pro)