Support

Account

Home Forums ACF PRO Can I use acf_form() to create a comment instead of a post? Reply To: Can I use acf_form() to create a comment instead of a post?

  • Hi @ryandorn

    To move the field, you need to use Javascript. It should be something like this:

    <script type="text/javascript">
    (function($) {
        
        $(document).ready(function(){
            
            $('.comment-form-comment').before( $('.acf-field-1234567890abc') );
            
        });
        
    })(jQuery);    
    </script>

    Where “.acf-field-1234567890abc” is based on your field key.

    To check if acf/save_post action hook is processing the comment, you can check if the post ID starts with “comment_”. Here’s an example how to do that:

    function my_acf_save_post( $comment_string_id ) {
        
        // Do it only for comment
        if( substr($comment_string_id, 0, 8) === 'comment_' ){
            update_field('field_name', 'the value', $comment_string_id);
        }
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Also, please check this page to learn how to get the value from a comment field: https://www.advancedcustomfields.com/resources/get-values-comment/.

    I hope this helps 🙂