user5122725
user5122725

Reputation:

How to get all WordPress pages associated with BuddyPress?

How to get all WordPress pages associated with BuddyPress? What I mean, I will elaborate it by an image below:

enter image description here

As everyone can see according to image there are 5 pages (Widgets, Testing Purpose, Home, About Us, Blog), these are the WordPress pages that are created by me and all these pages are assigned to BuddyPress component directory. Now I want to get all these assigned pages. Is there a builtin function for this purpose or is there any strategy to get these pages?

Upvotes: 1

Views: 110

Answers (1)

drew010
drew010

Reputation: 69967

You should be able to use the function bp_core_get_directory_page_ids which is defined in the file 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' ) {

It will return an array similar to:

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

The array values are the page ID's in WordPress which are assigned to those components.

Upvotes: 1

Related Questions