Home › Forums › ACF PRO › Upvote/Downvote System using ACF Pro › Reply To: Upvote/Downvote System using ACF Pro
I only use it to ‘upvote’ FAQ posts, not downvote, so only the upvote part is here but I think you get the idea and can create the downvote, based of this. Plus the output is written in twig instead of php but that’s not an issue I think.
Code in template (code is as is)
<div class="faq__helpful">
<h4>{{ __( 'Was this helpful', 'textdomain' ) }} ?</h4>
<div>
<form class="faq_helpful" action="" method="post">
<input type="hidden" name="post_id" value="{{ post.ID }}" />
<input type="hidden" name="sd_faq__nonce" value="{{ function( 'wp_create_nonce', 'sd-faq-nonce' ) }}" />
<button type="submit" name="helpful_yes" value="1" class="button item__delete-submit">
{{ __( 'YES', 'textdomain' ) }}
</button>
{% if helpful_yes %}
<small>{{ _n( '%s person found this helpful', '%s people found this helpful', helpful_yes, 'textdomain')|format(helpful_yes) }}</small>
{% endif %}
</form>
</div>
</div>
if ( isset( $_POST[ "sd_faq__nonce" ] ) ) {
if ( wp_verify_nonce( $_POST[ "sd_faq__nonce" ], 'sd-faq-nonce' ) ) {
// add helpful counter
if ( isset( $_POST[ "helpful_yes" ] ) && '1' == $_POST[ "helpful_yes" ] ) {
$faq_id = get_the_ID();
if ( $hf_yes == false ) {
update_post_meta( $faq_id, 'sd_helpful_yes', '1' );
} else {
$hf_yes = $hf_yes + 1;
update_post_meta( $faq_id, 'sd_helpful_yes', $hf_yes );
}
}
}
}
Since this is not an ACF issue/topic I don’t wanna get too deep into this. WordPress.stackexchange.com is a better place for all WP questions.
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!
ACF’s Repeater field is a versatile solution for repeating content in #WordPress.
— Advanced Custom Fields (@wp_acf) December 29, 2022
What’s your favorite use case for the Repeater field?
What’s the weirdest thing you’ve ever used it for?
Let us know!👇
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.