I would like to automate the process of adding descriptions for articles published on my site. I would like to automatically insert a random description from a list of pre-edited (Advanced Custom Fields) descriptions when a new post is published as draft. eg: "description_1" or "description_2" or "description_100" (randomly)
I have this code, which seems to do the trick, but I still have to insert the parameter to randomize the choice of description (randomly choose a number between 1 and 100 just after the word "description") on the line: // Custom post content $content = . $description_1 . ; of this code above. I would also like to add these two little conditions:
- The content of the article is empty
- The status of the article is set to "draft" Thanks for any response!
function show_update_postdata( $value, $post_id, $field ) {
// Get values from POST
$description_1 = $_POST['acf']['field_5dd00e0582125'];
$description_2 = $_POST['acf']['field_5dd00e0582125'];
$description_50 = $_POST['acf']['field_5dd00e0582125'];
$description_100 = $_POST['acf']['field_5dd00e0582125'];
// Custom post content
$content = . $description_1 . ;
$postdata = array(
'ID' => $post_id,
'post_content' => $content,
'post_type' => 'post',
);
wp_update_post( $postdata );
return $value;
}
add_filter('acf/update_value/name=description_1', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=description_2', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=description_50', 'show_update_postdata', 10, 3);
add_filter('acf/update_value/name=description_100', 'show_update_postdata', 10, 3);```