• Resolved stampdoor

    (@stampdoor)


    Hello, I am having trouble modifying the following.

    I changed it to post files with reference to number 28 in the FAQ, but when I prepare two file fields and send a file attachment in the first field only, the first attachment is also registered in the second field.

    How can I customize this?

    add_filter('cf7_2_post_metafield_file', 'change_meta_field_file_format', 10, 6);
    function change_meta_field_file_format( $file_format, $attachment_id, $post_id, $post_field, $form_field, $cf7_key ){
    /*
    * $file_format, default format is url path.
    * $attachment_id, file media attachment post id.
    * $post_id, form submission mapped to post.
    * $post_field, the meta post fields being saved.
    * $form_field, the form field from which it was submitted.
    * $cf7_key the current form being mapped.
    */
    $file_format = $attachment_id;
    return $file_format;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    each fiel field is a separate form field, you’ll need to filter them out in the php function you’re hooking.

    Thread Starter stampdoor

    (@stampdoor)

    Thank you for your reply.

    I followed your advice and added a process for when the file field is empty and it works as desired.

    add_filter('cf7_2_post_metafield_file', 'change_meta_field_file_format', 10, 6);
    function change_meta_field_file_format( $file_format, $attachment_id, $post_id, $post_field, $form_field, $cf7_key ){
    
    	if ( empty( $_FILES[$form_field]['name'] ) ) {
    		return '';
    	}
    	
        $file_format = $attachment_id . '_' . $form_field;
    
        return $file_format;
    
    }
    Plugin Author Aurovrata Venet

    (@aurovrata)

    Great, glad you got it working!

    If you’re using ACF on a regular basis and are doing custom work, maybe you may want to consider contributing a more permanent solution or the compatibility of this plugin, by submitting a PR on the GitHub repo.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.