bb_get_id_from_slug

The WordPress Core bb get id from slug function.

Description

bb_get_id_from_slug( $table, $slug, (int) $slug_length = 255 ); 

Parameters (3)

0. $table
The table.
1. $slug
The slug.
2. $slug_length — Optional. (int) => 255
The slug length.

Usage

  1. if ( !function_exists( 'bb_get_id_from_slug' ) ) { 
  2. require_once '/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // The table. 
  5. $table = null; 
  6.  
  7. // The slug. 
  8. $slug = null; 
  9.  
  10. // The slug length. 
  11. $slug_length = 255; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_get_id_from_slug($table, $slug, $slug_length); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_get_id_from_slug( $table, $slug, $slug_length = 255 ) { 
  2. global $bbdb; 
  3. $tablename = $table . 's'; 
  4.  
  5. list($_slug, $sql) = bb_get_sql_from_slug( $table, $slug, $slug_length ); 
  6.  
  7. if ( !$_slug || !$sql ) 
  8. return 0; 
  9.  
  10. return (int) $bbdb->get_var( "SELECT ${table}_id FROM {$bbdb->$tablename} WHERE $sql" );