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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.