BuddyPress:自定义配置文件日期字段未显示在循环中

时间:2012-07-19 14:37:46

标签: buddypress

我正在开发一个buddypress网站,允许会员发布会员目录中显示的广告,前提是他们也为其设置了过期日期。两个字段都只是扩展配置文件字段;广告是一个文本区域,过期日期当然是日期选择器。

在我的主题中,在members-loop.php循环中,我有以下代码:

// This one works
<?php $ad = bp_get_member_profile_data('field=Member Directory Ad'); ?>
// This one doesn't
<?php $ad_expiry = bp_get_member_profile_data('field=Member Directory Ad Expiration'); ?>

没有其他特殊代码可以实现这一目标。对于肯定已设置的成员,我认为$ ad_expiry为空是没有理由,特别是当$ ad具有正确的值时。

深入研究buddypress代码,bp_get_member_profile_data()不会返回我的扩展配置文件日期框数据。在xprofile_format_profile_field()中,值由bp_format_time()“格式化”,输出为空。所以我猜这是一个假的bug。

2 个答案:

答案 0 :(得分:2)

我至少弄明白了这个错误。 BuddyPress将日期框的输出存储为类似“2012-07-19 00:00:00”的字符串。 bp_get_member_profile_data()从数据库中检索它,然后将其传递给xprofile_format_profile_field(),它将它传递给bp_format_time(),后者返回false,因为该值未通过is_numeric()检查。

答案 1 :(得分:1)

尝试此解决方法 -

  //you need to specify the $user_id
$ad_expiry = xprofile_get_field_data('Member Directory Ad Expiration', $user_id );  
  // reformat, if you like
$ad_expiry  = strtotime($ad_expiry);
echo date('m/d/Y', $ad_expiry); 

感谢有关trac的错误报告。

相关问题