如何获得与BuddyPress相关的所有WordPress页面?

时间:2015-10-19 20:06:06

标签: php wordpress buddypress

如何获取与BuddyPress相关的所有WordPress页面?我的意思是,我将通过下面的图片详细说明:

enter image description here

每个人都可以根据图像看到有5个页面(小部件,测试目的,主页,关于我们,博客),这些是由我创建的WordPress页面,所有这些页面都分配给BuddyPress组件目录。现在我想获得所有这些分配的页面。是否有用于此目的的内置函数或是否有任何策略来获取这些页面?

1 个答案:

答案 0 :(得分:1)

您应该能够使用文件bp_core_get_directory_page_ids中定义的函数bp-core/bp-core-functions.php

/**
 * Fetch a list of BP directory pages from the appropriate meta table.
 *
 * @since BuddyPress (1.5.0)
 *
 * @param string $status 'active' to return only pages associated with active components, 'all' to return all saved
 *                       pages. When running save routines, use 'all' to avoid removing data related to inactive
 *                       components. Default: 'active'.
 * @return array|string An array of page IDs, keyed by component names, or an
 *                      empty string if the list is not found.
 */
function bp_core_get_directory_page_ids( $status = 'active' ) {

它将返回类似于:

的数组
array(4) {
  ["activity"]=>
  int(72)
  ["members"]=>
  int(73)
  ["register"]=>
  int(74)
  ["activate"]=>
  int(75)
}

数组值是WordPress中分配给这些组件的页面ID。