Home › Forums › ACF PRO › True/False – Only allow one post to have true value › Reply To: True/False – Only allow one post to have true value
Hi John,
Thank you for your reply. I’m using ACF PRO, so ACF5. I switched out $_POST['fields']
with $_POST['acf']
but unfortunately my code is still not working. Saving an post as featured, doesn’t unset the featured option on a different post.
So my code now looks like:
function my_acf_save_post( $post_id ){
$fields = false;
if ( isset( $_POST['acf'] ) ) {
$fieldId = 'field_5b51ec43f331a';
$fields = $_POST['acf'];
$featuredArticle = $fields[$fieldId];
if ( $featuredArticle ) {
$args = array(
'post_type' => array('post'),
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
'compare' => '=='
)
)
);
$post_query = new WP_Query( $args );
if ( $post_query->have_posts() ) {
while ( $post_query->have_posts() ) {
$post_query->the_post();
acf_update_field( $fieldId, false, get_the_ID() );
}
}
}
}
} // end my_acf_save_post
add_action('acf/save_post', 'my_acf_save_post', 1);
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.