bbp_query_post_parent__in

Adds ability to include or exclude specific post_parent ID's.

Description

(string) bbp_query_post_parent__in( (string) $where, (string) $object = '' ); 

Returns (string)

Parameters (2)

0. $where (string)
The where.
1. $object — Optional. (string) => ''
The object.

Usage

  1. if ( !function_exists( 'bbp_query_post_parent__in' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // The where. 
  5. $where = ''; 
  6.  
  7. // The object. 
  8. $object = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_query_post_parent__in($where, $object); 
  12.  

Defined (1)

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

/includes/common/functions.php  
  1. function bbp_query_post_parent__in( $where, $object = '' ) { 
  2. global $wpdb, $wp; 
  3.  
  4. // Noop if WP core supports this already 
  5. if ( in_array( 'post_parent__in', $wp->private_query_vars ) ) 
  6. return $where; 
  7.  
  8. // Bail if no object passed 
  9. if ( empty( $object ) ) 
  10. return $where; 
  11.  
  12. // Only 1 post_parent so return $where 
  13. if ( is_numeric( $object->query_vars['post_parent'] ) ) 
  14. return $where; 
  15.  
  16. // Including specific post_parent's 
  17. if ( ! empty( $object->query_vars['post_parent__in'] ) ) { 
  18. $ids = implode( ', ', wp_parse_id_list( $object->query_vars['post_parent__in'] ) ); 
  19. $where .= " AND {$wpdb->posts}.post_parent IN ($ids)"; 
  20.  
  21. // Excluding specific post_parent's 
  22. } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) { 
  23. $ids = implode( ', ', wp_parse_id_list( $object->query_vars['post_parent__not_in'] ) ); 
  24. $where .= " AND {$wpdb->posts}.post_parent NOT IN ($ids)"; 
  25.  
  26. // Return possibly modified $where 
  27. return $where;