Reputation: 75
I've got this far with some PHP to display a repeatable field but the output just displayed Array
Any ideas would be greatly appreaciated:
<?php
$repeatable = get_post_meta( get_the_ID(), 'ecpt_eventdaytime', true);
if( !empty($repeatable )) {
echo '<img src="/wp-content/uploads/2013/02/Time.gif">';
echo $repeatable ;
echo "<br><br>";
}
?>
Upvotes: 0
Views: 957
Reputation: 111
If ecpt_eventdaytime
is array then:
<?php
$repeatable = get_post_meta( get_the_ID(), 'ecpt_eventdaytime', true);
if( !empty($repeatable )) {
foreach($repeatable as $value) {
echo '<img src="/wp-content/uploads/2013/02/Time.gif">';
echo $value;
echo "<br><br>";
}
}
?>
Upvotes: 0
Reputation: 5823
Try it like this:
<?php if (have_posts()) :
while (have_posts()) : the_post();
$repeatable = get_post_meta( get_the_ID(), "ecpt_eventdaytime", true );
echo $repeatable ;
endwhile;
endif;
?>
Or if you want to display a custom field value outside the loop, simply use the following code. The thing is, you simply need the ID.
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'ecpt_eventdaytime', true);
?>
Upvotes: 1
Reputation: 57322
because get_post_meta
return array you need to use loop
Quoting from wordpress
<?php $meta_values = get_post_meta($post_id, $key, $single); ?>
Return Value
- If only $id is set it will return all meta values in an associative array.
- If $single is set to false, or left blank, the function returns an array containing all values of the specified key.
- If $single is set to true, the function returns the first value of the specified key (not in an array)
Upvotes: 0