呼叫get_post_custom在屏幕上输出 38


Calling get_post_custom outputs 38 on screen

当我在循环中调用get_post_custom时,它工作正常。但它在我的屏幕上打印了 38。是wp错误还是什么?我该如何解决它?

更多信息:当我打电话给get_post_meta时也会发生这种情况。我正在使用自定义字段模板插件。

$args = array(
        'post_type' => 'attendeeaddress',
        'meta_query' => array(
            array(
                'key' => 'MEETING_ID',
                'value' => $meeting_id,
                'meta_compare' => '='
            )
        )
    );
    $wpquery = new WP_Query($args);
    $addresses = array();
    while ( $wpquery->have_posts() ) : $wpquery->the_post();
        $custom_val = get_post_custom(the_ID());
        $addresses[] = array(
            "address" => $custom_val["MEETING_ADDRESS"][0],
            "meeting_id" => $meeting_id,
            "lat" => $custom_val["MEETING_LAT"][0],
            "lon" => $custom_val["MEETING_LON"][0],
            "name" => $custom_val["NAME"][0]
        );
    endwhile;
    return $addresses;

这是因为the_ID();实际上"回显"了该值。

要只收集值,请使用 get_the_ID();

http://codex.wordpress.org/Function_Reference/the_IDhttp://codex.wordpress.org/Function_Reference/get_the_ID

  • 您只能在循环中使用它。