0

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>";
}
?> 
4

3 回答 3

1

试试这样:

<?php if (have_posts()) :
      while (have_posts()) : the_post(); 
        $repeatable = get_post_meta( get_the_ID(), "ecpt_eventdaytime", true ); 
        echo $repeatable ;
      endwhile;
      endif;
?>

或者,如果您想在循环外显示自定义字段值,只需使用以下代码。问题是,您只需要 ID。

<?php 
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'ecpt_eventdaytime', true);
?>
于 2013-02-16T16:59:18.613 回答
0

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)
于 2013-02-16T16:57:24.643 回答
0

如果ecpt_eventdaytime是数组,则:

<?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>";
    }
}
?> 
于 2013-02-17T00:01:05.590 回答