Home Forums Front-end Issues Arrange fields according to drag & drop


Arrange fields according to drag & drop

  • Hello,
    I have a function to display all the fields with content in a specific post:

    function woo_new_product_tab_content() {
    // The new tab content
    $prod_id = get_the_ID();
    $fields = get_fields();

    if( $fields ){ ?>

      <?php foreach( $fields as $name => $value ):
      $field_name = $name;

      $field1 = get_field_object($field_name);
      if ($value){ ?>

    • <b><u><?php echo $field1[‘label’]; ?></u></b><br> <?php echo $field1[‘value’]; ?>
    • <?php }
      endforeach; ?>

    <?php }

    The problem is that the order that the fields appear on the page is according to the time I created the field.

    I want the fields to appear according to the order on the admin panel (ordered with drag&drop), Is that possible?

  • Basically, no. ACF uses get_post_meta() without a $key and the values are returned in the order returned by this function.

    If you want them to be displayed in a specific order this is something you’ll need to deal with.

    You might try get_field_objects(), but to be honest, I don’t know what order these are returned in. It could be the same.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.