Home Forums General Issues Displaying Array Data in Product Pages Reply To: Displaying Array Data in Product Pages

  • I imported all products from csv. They are visible in products admin section. The custom fields had been set up before import and the field values were imported too. The problem I had was displaying those labels (keys) and fields (values) on the products webpage, but only those labels and fields that were not empty. I have over 3000 extremely varied products and 29 fields and only a third of those fields were relative to any one product at any time. However, having spent a lot of time trying to find an answer I managed to sort it out using the following and placed the code in my template. Now all I have to do is complete a php course so it doesn’t take two weeks to find 10 lines of code! Thanks for your responses.


    $fields = get_field_objects(); ?>

    <?php if( $fields ): ?>

      <?php foreach( $fields as $field ): ?>

      <?php if( $field[‘value’] ): ?>

    • <?php echo $field[‘label’]; ?>: <?php echo $field[‘value’]; ?>
    • <?php endif; ?>

      <?php endforeach; ?>

    <?php endif; ?>