Home › Forums › General Issues › How can i update my subfields › Reply To: How can i update my subfields
Thanks, yes i tried this approach and it doesn’t work for me. I updated these fields with update_post_meta
but now i can see these fields values only on post edit page. And function get_fields
cant get their values. If i click update post then function works correctly. But i cant update all the posts using this approach, there are about 8000 posts.
I used this code to update the fields
function some_field_update(){
$my_posts = new WP_Query;
$myposts = $my_posts->query( array(
'post_type' => 'product',
'posts_per_page' => 10000,
) );
foreach( $myposts as $pst ){
if ($pst){
update_post_meta($pst->ID, 'main_specifications_colors', get_post_meta($pst->ID, 'colors')[0]);
}
}
}
add_action('init', 'some_field_update');
And this code i use to display the values
$fields = get_fields($product_id);
?>
<?php if( $fields ): ?>
<?php foreach( $fields as $name => $value ):
$field = get_field($name, $product_id);
if (array_filter($field)){
echo '<h2>'.ucwords(str_replace('_', ' ', $name)).':</h2>';
echo '<table>';
foreach ($field as $key => $val){
if($val){
echo '<tr><td>'. ucwords(str_replace('_', ' ', $key)).': </td>';
echo '<td>'. ucwords(str_replace('_', ' ', $val)).'</td></tr>';
}
}
echo '</table>';
}
?>
<?php endforeach; ?>
<?php endif;
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 Chat Fridays”
— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 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.