我在一个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代码,我的扩展配置文件datebox数据不会被bp_get_member_profile_data()返回。在xprofile_format_profile_field()中,bp_format_time()对值进行了“格式化”,并且输出为空。所以我猜这是buddypress的一个bug。
发布于 2012-07-22 04:12:44
尝试此解决方法-
//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上的bug报告。
发布于 2012-07-20 00:43:23
至少我已经找出了bug。BuddyPress将日期框的输出存储为类似于"2012-07-19 00:00:00“的字符串。bp_get_member_profile_data()从数据库中检索该值,然后将其传递给xprofile_format_profile_field(),后者将其传递给bp_format_time(),bp_format_time()返回false,因为该值未通过is_numeric()检查。
https://stackoverflow.com/questions/11563198
复制相似问题