24 lines
956 B
PHP
24 lines
956 B
PHP
<?php
|
|
|
|
// Function to update features image of posts depending on its type , to get used for og:image
|
|
// Currently commented because not working with the current svg version of thematiques pictures
|
|
|
|
// add_action('save_post', 'flex_FeaturedImageSetByACF');
|
|
function flex_FeaturedImageSetByACF()
|
|
{
|
|
global $post;
|
|
if (!$post) return;
|
|
|
|
if ($post->post_type === 'conseils') {
|
|
$currentThematique = get_the_terms($post->ID, 'thematiques') ? get_the_terms($post->ID, 'thematiques')[0] : null;
|
|
$mainThematique = getMainThematique($currentThematique) ?? null;
|
|
if (!$mainThematique) return;
|
|
|
|
$mainThematiqueFr = apply_filters('wpml_object_id', $mainThematique->term_id, 'thematiques', TRUE, 'fr');
|
|
$thematique_picture = get_field('taxonomy_pictures', "thematiques_" . $mainThematiqueFr)['illustration_s'] ?? null;
|
|
if (!$thematique_picture) return;
|
|
|
|
add_post_meta($post->ID, '_thumbnail_id', $thematique_picture['ID']);
|
|
};
|
|
}
|