bp_get_query_template

Retrieve the path to a template.

Description

(string) bp_get_query_template( (string) $type, (array) $templates = array() ); 

Used to quickly retrieve the path of a template without including the file extension. It will also check the parent theme and theme-compat theme with the use of . Allows for more generic template locations without the use of the other get_*_template() functions.

Returns (string)

Full path to file.

Parameters (2)

0. $type (string)
Filename without extension.
1. $templates — Optional. (array) => array()
An optional list of template candidates.

Usage

  1. if ( !function_exists( 'bp_get_query_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template-loader.php'; 
  3.  
  4. // Filename without extension. 
  5. $type = ''; 
  6.  
  7. // An optional list of template candidates. 
  8. $templates = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_get_query_template($type, $templates); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-template-loader.php  
  1. function bp_get_query_template( $type, $templates = array() ) { 
  2. $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 
  3.  
  4. if ( empty( $templates ) ) { 
  5. $templates = array( "{$type}.php" ); 
  6.  
  7. /** 
  8. * Filters possible file paths to check for for a template. 
  9. * This is a variable filter based on the type passed into 
  10. * bp_get_query_template. 
  11. * @since 1.7.0 
  12. * @param array $templates Array of template files already prepared. 
  13. */ 
  14. $templates = apply_filters( "bp_get_{$type}_template", $templates ); 
  15.  
  16. // Filter possible templates, try to match one, and set any BuddyPress theme 
  17. // compat properties so they can be cross-checked later. 
  18. $templates = bp_set_theme_compat_templates( $templates ); 
  19. $template = bp_locate_template( $templates ); 
  20. $template = bp_set_theme_compat_template( $template ); 
  21.  
  22. /** 
  23. * Filters the path to a template file. 
  24. * This is a variable filter based on the type passed into 
  25. * bp_get_query_template. 
  26. * @since 1.7.0 
  27. * @param string $template Path to the most appropriate found template file. 
  28. */ 
  29. return apply_filters( "bp_{$type}_template", $template );