Viewing 3 reply threads
  • Author
    Posts
    • #3062
      azizultex
      Member

      Howdy,
      I am trying to get the value of Add More from setting page. I am able to get result from Basic Add More using below code:

      $settings = get_option('my_theme_settings');
      $exercises = $settings['exercise'];
      
      echo '<ul>';
      foreach ($exercises as $exercise)
      	{
      	  echo "<li> $exercise </li>";
      	}	
      echo '</ul>';

      for the Advanced Add More, I am trying to get the result using something like this:

      $settings = get_option('my_theme_settings');
      $workout_schedules = $settings['workout_schedule'];
      		
      echo '<ul>';
      
      foreach ( $workout_schedules as $schedule )
      	{ 
      		$days = $schedule['day'];
      
      		foreach ($days as $day )
      		{
      			echo "Day: $day <br/>";
      		}
      		
      		$exercise_days = $schedule['exercise_day'];
      		
      		foreach ($exercise_days as $exercise_day )
      		{
      			$exercise_reps = $exercise_day['exercise_reps'];
      			$exercise_sets = $exercise_day['exercise_sets'];
      			$exercise_name = $exercise_day['exercise'];
      			
      			echo "Exercise: $exercise_name, Recipe: $exercise_reps , Sets: $exercise_sets ";
      		}
      		
      	}	
       
      
      echo '</ul>';

      But this not working. How can I show the result?

      Thanks

    • #3063
      Steve
      Keymaster

      Advanced Add-mores are multi-layered. Please read the docs and let us know if it helps.

    • #3131
      azizultex
      Member

      Hi,
      I am sorry for the delay to reply you. I tried today, but couldn’t get it worked.

      I used below code in my metabox that is showing field in post types.

      <?php
      /*
      Title: My Metabox
      Description: My cool new metabox
      Post Type: post
      */
      
      // Let's create a text box field
      
        piklist('field', array(
          'type' => 'text'
          ,'field' => 'exercise'
          ,'add_more' => true
          ,'label' => __('Workout')
        ));
       
      ?>

      I used below code in my single.php file after the_content()

      								
      			<?php
      			// Get field data
      			$exercise = get_post_meta($post->ID, 'exercise', true);
      			 
      			// Get your custom template part: addmore-workout-template.php
      			piklist(get_stylesheet_directory() . '/piklist/add-more-templates/addmore-workout-template', array('data' => $exercise, 'loop' => 'data'));
      			?>
      			

      and addmore-workout-template.php file looks like this: <?php echo $data['exercise']; ?>

      Finally, I receive this error: http://s21.postimg.org/w3o9q8b4n/screenshot_163.png

      Where am I doing wrong?

    • #3140
      Steve
      Keymaster

      @azizultex– This is really a different post. Your first one was ADVANCED Add-more’s… this is clearly a SIMPLE Add-More. In the future please create a new ticket.

      All you need to do here is:

      $exercises = get_post_meta($post->ID, 'exercise');
      
      foreach ($exercises as $exercise => $value)
      {
        echo $value;
      }
      
Viewing 3 reply threads
  • You must be logged in to reply to this topic.