Viewing 2 reply threads
  • Author
    Posts
    • #5098
      sancreative
      Member

      Hi There,

      Im just trying to follow some of your demo’s to get a feel of piklist before adding it to some projects I’m working on.

      I followed along with the repeater field demo in the doc’s and keep getting an error while trying to display the fields on frontend.

      I’ve kept it simple with the beasic example.

      code in metaboxes file assigned to pages

      <?php
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'exercise'
          ,'add_more' => true
          ,'label' => __('Workout')
        ));
       
      ?>

      code in page.php

      <?php
      // Get field data
      $exercise = get_post_meta($post->ID, 'exercise', true);
       
      // Get your custom template part: addmore-workout-template.php
      piklist(piklist::$paths['distincthq-builder'] . '/addmore-workout-template', array('data' => $exercise, 'loop' => 'data'));
      ?>

      and finally code in addmore-workout-template.php (placed in the plugin dir)

      <div class="test"><?php echo $data['exercise']; ?></div>

      the result:

      Warning: Illegal string offset ‘exercise’ in /home/dh2serve/public_html/dev/wp-content/plugins/distincthq-builder/addmore-workout-template.php on line 1
      M

      screenshots of my page custom fields attached

      Attachments:
      You must be logged in to view attached files.
    • #5101
      Steve
      Keymaster

      @sancreative– I suggest you use the latest beta, v0.9.9.x.

      Once you upgrade, you will not longer need to use this code:

      piklist(piklist::$paths['distincthq-builder'] . '/addmore-workout-template', array('data' => $exercise, 'loop' => 'data'));
      

      You will be able to just loop through the data like this:

      $exercises = get_post_meta($post->ID, 'exercise', false);
      
      foreach ($exercises as $exercise => $value)
      {
        echo "<div class='test'>" . $value . "</div>";
      }
      
    • #5102
      sancreative
      Member

      thanks for the code example, works perfect.

      I was using the latest beta version Piklist v0.9.9.6

Viewing 2 reply threads
  • The topic ‘Repeater Field’ is closed to new replies.