在管理员发布仪表板中显示ACF字段

时间:2018-09-04 作者:Deepak Kamat

正在寻找在管理列中显示帖子的ACF数据的方法,使用manage_posts_columns

在我的functions.php 我有这个:

function custom_columns( $columns ) {
    $columns = array(
        \'cb\' => \'<input type="checkbox" />\',
        \'title\' => \'Title\',
        \'featured_image\' => \'Image\',
        \'categories\' => \'Categories\',
        \'amazon_url\' => \'Amazon Link\',
        \'comments\' => \'<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>\',
        \'date\' => \'Date\'
     );
    return $columns;
}

add_filter(\'manage_posts_columns\' , \'custom_columns\');

function custom_columns_data( $column, $post_id ) {
    switch ( $column ) {
    case \'featured_image\':
        the_post_thumbnail( \'thumbnail\' );
        break;
    case \'amazon_url\' :
         echo get_field( \'product_url\', $post_id );
         break;
    }
}

add_action( \'manage_posts_custom_column\' , \'custom_columns_data\', 10, 2 ); 
我想要ACF字段,它是product_url 对于帖子列表的管理仪表板中出现的每一篇帖子,“亚马逊链接”列都在那里,但似乎根本没有数据。

1 个回复
SO网友:Deepak Kamat

此代码运行得非常好:

  function custom_columns( $columns ) {
        $columns = array(
            \'cb\' => \'<input type="checkbox" />\',
            \'title\' => \'Title\',
            \'featured_image\' => \'Image\',
            \'categories\' => \'Categories\',
            \'amazon_url\' => \'Amazon Link\',
            \'comments\' => \'<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>\',
            \'date\' => \'Date\'
         );
        return $columns;
    }

    add_filter(\'manage_posts_columns\' , \'custom_columns\');

    function custom_columns_data( $column, $post_id ) {
        switch ( $column ) {
        case \'featured_image\':
            the_post_thumbnail( \'thumbnail\' );
            break;
        case \'amazon_url\' :
             echo get_field( \'product_url\', $post_id );
             break;
        }
    }

    add_action( \'manage_posts_custom_column\' , \'custom_columns_data\', 10, 2 ); 
我意识到有一个拼写错误

case \'anazon_url\' : (不过我在问题中更新了它)

是的case \'anazon_url\' :

即使在修复了打字错误后,它仍然不起作用,但后来我清除了缓存并再次尝试,它仍然起作用!

所以我把代码留在这里,如果有人想在管理列中显示ACF数据,请点击这里!

结束

相关推荐

在管理员发布仪表板中显示ACF字段 - 小码农CODE - 行之有效找到问题解决它

在管理员发布仪表板中显示ACF字段

时间:2018-09-04 作者:Deepak Kamat

正在寻找在管理列中显示帖子的ACF数据的方法,使用manage_posts_columns

在我的functions.php 我有这个:

function custom_columns( $columns ) {
    $columns = array(
        \'cb\' => \'<input type="checkbox" />\',
        \'title\' => \'Title\',
        \'featured_image\' => \'Image\',
        \'categories\' => \'Categories\',
        \'amazon_url\' => \'Amazon Link\',
        \'comments\' => \'<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>\',
        \'date\' => \'Date\'
     );
    return $columns;
}

add_filter(\'manage_posts_columns\' , \'custom_columns\');

function custom_columns_data( $column, $post_id ) {
    switch ( $column ) {
    case \'featured_image\':
        the_post_thumbnail( \'thumbnail\' );
        break;
    case \'amazon_url\' :
         echo get_field( \'product_url\', $post_id );
         break;
    }
}

add_action( \'manage_posts_custom_column\' , \'custom_columns_data\', 10, 2 ); 
我想要ACF字段,它是product_url 对于帖子列表的管理仪表板中出现的每一篇帖子,“亚马逊链接”列都在那里,但似乎根本没有数据。

1 个回复
SO网友:Deepak Kamat

此代码运行得非常好:

  function custom_columns( $columns ) {
        $columns = array(
            \'cb\' => \'<input type="checkbox" />\',
            \'title\' => \'Title\',
            \'featured_image\' => \'Image\',
            \'categories\' => \'Categories\',
            \'amazon_url\' => \'Amazon Link\',
            \'comments\' => \'<span class="vers"><div title="Comments" class="comment-grey-bubble"></div></span>\',
            \'date\' => \'Date\'
         );
        return $columns;
    }

    add_filter(\'manage_posts_columns\' , \'custom_columns\');

    function custom_columns_data( $column, $post_id ) {
        switch ( $column ) {
        case \'featured_image\':
            the_post_thumbnail( \'thumbnail\' );
            break;
        case \'amazon_url\' :
             echo get_field( \'product_url\', $post_id );
             break;
        }
    }

    add_action( \'manage_posts_custom_column\' , \'custom_columns_data\', 10, 2 ); 
我意识到有一个拼写错误

case \'anazon_url\' : (不过我在问题中更新了它)

是的case \'anazon_url\' :

即使在修复了打字错误后,它仍然不起作用,但后来我清除了缓存并再次尝试,它仍然起作用!

所以我把代码留在这里,如果有人想在管理列中显示ACF数据,请点击这里!

相关推荐