• Resolved onyudo

    (@onyudo)


    I am using Tammy Hart’s amazing code from here, but for the life of me I cannot figure out how to display the data captured in a Repeatable Text Meta Box.

    Would anybody out there be willing to point me in the right direction?

    Cheers!

    /Martin

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,
    If you didn’t solve it stll – use echo get_post_meta($post_id); to see all the meta fields, and you’ll notice that under your repeatable fields key there is a array, so use for that array, for example:

    foreach($repeatable_keys as $each_key) {
       echo $each_key
    }

    This is just out of my head, without checking actual outputs …

    Thread Starter onyudo

    (@onyudo)

    I can get all of the data to output using the get_post_meta command, but i’m dead in the water after that. I see the logic of the code you’ve suggested, but instead of outputting the word “Array” I get absolutely nothing on the front end at all. Thanks for making a suggestion, though. It is genuinely appreciated!

    Thread Starter onyudo

    (@onyudo)

    ok, so thanks to your code i have made some progress. at this point i am at least getting the word “Array” outputting on the front end for each entry into a repeatable field on the back end.

    my repeatable metabox is for a list of ingredients, and is set up like this:

    array( // Repeatable & Sortable Text inputs
    		'label'	=> 'Ingredients', // <label>
    		'desc'	=> 'Ingredients', // description
    		'id'	=> $prefix.'ingredients', // field id and name
    		'type'	=> 'repeatable', // type of field
    		'sanitizer' => array( // array of sanitizers with matching kets to next array
    			'featured' => 'meta_box_santitize_boolean',
    			'title' => 'sanitize_text_field',
    			'desc' => 'wp_kses_data'
    		),
    		'repeatable_fields' => array ( // array of fields to be repeated
    			'title' => array(
    				'label' => 'Ingredient',
    				'id' => 'ingredient',
    				'type' => 'text'
    			),
    		)
    	),

    the code i am using to try to output the information to the front is this:

    <div id="ingredients">
            		<h3>Ingredients</h3>
            			<?php
    						$recipe_ingredients = get_post_meta($post->ID, 'recipe_ingredients', true); {
    
    						echo '<ul class="custom_repeatable">';
    
    						foreach ($recipe_ingredients as $ingredients) {
    							echo '<li>'.$ingredients.'</li>';
    						}
    
    						echo '</ul>';
    						}
    					?>
            	</div>

    My test entry in the backend only has 3 ingredients, but the result is only the word “Array” output 3 times in an unordered list.

    When i call all meta info I get this as a result:

    recipe_ingredients: a:3:{i:0;a:1:{s:10:”ingredient”;s:17:”1 Stick of Butter”;} i:1;a:1:{s:10:”ingredient”;s:6:”3 Eggs”;} i:2;a:1:{s:10:”ingredient”;s:12:”1/2 Cup Milk”;}}

    Thread Starter onyudo

    (@onyudo)

    finally, success!

    <div id="ingredients">
    				<h3>Ingredients</h3>
    					<?php
    						$recipe_ingredients = get_post_meta($post->ID, 'recipe_ingredients', true); {
    
    						echo '<ul class="custom_repeatable">';
    
    						foreach ($recipe_ingredients as $ingredients) {
    							echo '<li>';
    
    							foreach($ingredients as $i=>$value) {
    								echo $value;
    							}
    
    							echo '</li>';
    
    							}
    
    						echo '</ul>';
    						}
    					?>
    			</div>

    i’m sure there are much better ways to do this, but the correct data is getting to the front end now.

    many thanks anydog for pointing me in the right direction.

    /martin

    Thread Starter onyudo

    (@onyudo)

    resolved!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Tammy Hart's Reusable Custom WP Meta Boxes – Repeatable Fields’ is closed to new replies.