【问题标题】:Wordpress - ACF $array->ID not bringing anything?Wordpress - ACF $array->ID 没有带来任何东西?
【发布时间】:2014-07-22 23:10:42
【问题描述】:

我正在使用高级自定义字段,并且我在转发器中有一个“关系字段”,管理员可以在其中选择用户。

这段代码成功地带来了数组,但我不明白为什么$idinverx = $inverx->ID; 不起作用。

我知道这可能很基本,但我以前做过很多次,我不知道为什么它不起作用,有人可以帮助我吗?这是我的代码:

wp_reset_query();

$args2 = array(
    'post_type' => 'inversion',
);

$the_query2 = new WP_Query( $args2 );

if ( have_posts() ) : 

    while ( $the_query2->have_posts() ) : $the_query2->the_post(); 

        if( have_rows('comisiones') ):

            while ( have_rows('comisiones') ) : the_row();
            {
                $inverx = get_sub_field('inversionista_que_recibe_comision_de_esta_inversion');
                print_r($inverx); // I get an array displayed here
                $idinverx = $inverx->ID;
                echo $idinverx; // Nothing gets displayed... why? :(
            }

?> 

<?php
            endwhile;

        else:
        // no rows found

        endif;

?>

<?php endwhile; else: ?>

    <p>No hay Inversiones</p>

<?php endif; ?>

这就是$inverx 里面的内容:

Array ( 
    [ID] => 3 
    [user_firstname] => roberto 
    [user_lastname] => lozano 
    [nickname] => roberto 
    [user_nicename] => roberto 
    [display_name] => roberto lozano 
    [user_email] => roberto123@hotmail.com 
    [user_url] => http://roberto.com 
    [user_registered] => 2014-06-23 18:17:56 
    [user_description] => 
    [user_avatar] =>  
)

【问题讨论】:

    标签: php wordpress advanced-custom-fields


    【解决方案1】:

    $idinverx 是一个数组,所以你不应该把它当作一个对象。 而不是使用:

    $idinverx = $inverx->ID
    

    你应该使用:

    $idinverx = $inverx['ID'];
    

    【讨论】:

    • 我很高兴你现在可以继续前进 =)
    猜你喜欢
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 2021-01-16
    • 2021-10-29
    相关资源
    最近更新 更多