Home Forums Front-end Issues Select multiple images and attach to post content


Select multiple images and attach to post content

  • Hi,

    I have created frontend to create post in thread, I using ACF 4.4.2:

    When I upload multiple files frontend, I can not multiple select images.

    How to select multiple image from Field type “Image” & attach images to post content?

    This is my code:

    <?php acf_form_head(); ?>
    Template Name: dangbai
    <div id="content">
    	<?php while ( have_posts() ) : the_post(); ?>
    				'post_id'		  => 'new_post',
    				'submit_value'	  => 'Đăng bài',
    				'field_groups'	  => array( 305 ),
    				'updated_message' => 'Đã đăng bài'
    	<?php endwhile; ?>	
    <?php get_footer(); ?>


    function my_pre_save_post( $post_id ) {
    	// bail early if not a new post
    	if( $post_id !== 'new_post' ) {	 
    		return $post_id;	
    	// vars
    	$title = $_POST['fields']['field_5558a08e10eed'];
    	// Create a new post
    	$post = array(
    		'post_status'	=> 'publish',
    		'post_type'		=> 'post',
    		'post_title'	=> $title
    	// insert the post
    	$post_id = wp_insert_post( $post ); 
    	// update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
    	// return the new ID
    	return $post_id;
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );
    *Save ACF image field to post Featured Image 
    // run before ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    function my_acf_save_post( $post_id ) {
        // bail early if no ACF data
        if( empty($_POST['fields']) ) {   
        // specific field value
        $image = $_POST['fields']['field_5558a53d6c205'];
    		// Bail if image field is empty
    	if ( empty($image) ) {
    	// 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', $image );


  • I think I may be a little confused about what you’re trying to do.

    An ACF Image field only allows selecting a single image. And as far as I know a post can only have one post_thumbnail add_post_meta( $post_id, '_thumbnail_id', $image );

    To select multiple images you’d need to use a repeater to allow adding multiple images in the form.

    If you want to add multiple attachments to a post then you should look at

    If I’m misunderstanding please explain a bit more about what it is you’re trying to do.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Select multiple images and attach to post content’ is closed to new replies.