【问题标题】:BuddyPress: Custom profile date field not showing in loopBuddyPress:自定义个人资料日期字段未在循环中显示
【发布时间】:2012-07-19 14:37:45
【问题描述】:

我正在开发一个 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() “格式化”,输出为空。所以我猜这是一个 buddypress 错误。

【问题讨论】:

    标签: buddypress


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      试试这个解决方法 -

        //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 的错误报告。

      【讨论】:

      • 谢谢。我最终使用了 strtotime($members_template->member->profile_data['Member Directory Ad Expiration']['field_data'])
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      相关资源
      最近更新 更多