BBP_Shortcodes::display_search( array $attr, string $content = '' )
Display the contents of search results in an output buffer and return to ensure that post/page contents are displayed first.
Description
Parameters
- $attr
-
(Required)
- $content
-
(Optional)
Default value: ''
Source
File: bp-forums/common/shortcodes.php
public function display_search( $attr, $content = '' ) {
// Sanity check required info
if ( !empty( $content ) ) {
return $content;
}
// Bail if search is disabled
if ( ! bbp_allow_search() ) {
return;
}
// Trim search attribute if it's set
if ( isset( $attr['search'] ) ) {
$attr['search'] = trim( $attr['search'] );
}
// Set passed attribute to $search_terms for clarity
$search_terms = empty( $attr['search'] ) ? bbp_get_search_terms() : $attr['search'];
// Unset globals
$this->unset_globals();
// Set terms for query
set_query_var( bbp_get_search_rewrite_id(), $search_terms );
// Start output buffer
$this->start( bbp_get_search_rewrite_id() );
// Output template
bbp_get_template_part( 'content', 'search' );
// Return contents of output buffer
return $this->end();
}
Changelog
| Version | Description |
|---|---|
| bbPress (r4579) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.