A
A
Alexander Mishchenko2020-08-14 23:32:01
WordPress
Alexander Mishchenko, 2020-08-14 23:32:01

How to update custom fields via update_field?

There is a code with which I select all posts and update the service field in them. But the problem is that a post, for example, has 5 services, but the first service is taken and duplicated. Tell me what am I doing wrong?

$recent2 = new WP_Query(
    array(
      'orderby' => '',
      'showposts'=>-1,
       )
  );
      while($recent2->have_posts()) : $recent2->the_post() ;
        $count = get_field('uslugi');
        update_field('uslugi', $count);
      ?>
  <?php endwhile; ?>
  <?php wp_reset_query() ; ?>

When updating an additional field in which there is only 1 value, everything is ok. If there are several values ​​(for example, a custom field of the taxonomy type), then the first value is taken and duplicated.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question