pmpro_posts_where_unhide_cats

Find taxonomy filters and make sure member categories are not hidden from members.

Description

pmpro_posts_where_unhide_cats( $where ); 

Parameters (1)

0. $where
The where.

Usage

  1. if ( !function_exists( 'pmpro_posts_where_unhide_cats' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/content.php'; 
  3.  
  4. // The where. 
  5. $where = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_posts_where_unhide_cats($where); 
  9.  

Defined (1)

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

/includes/content.php  
  1. function pmpro_posts_where_unhide_cats($where) 
  2. global $pmpro_my_cats, $wpdb; 
  3.  
  4. //if we have member cats, make sure they are allowed in taxonomy queries 
  5. if(!empty($where) && !empty($pmpro_my_cats)) 
  6. $pattern = "/$wpdb->posts.ID NOT IN \(\s*SELECT object_id\s*FROM dev_term_relationships\s*WHERE term_taxonomy_id IN \((.*)\)\s*\)/"; 
  7. $replacement = $wpdb->posts . '.ID NOT IN ( 
  8. SELECT tr1.object_id 
  9. FROM ' . $wpdb->term_relationships . ' tr1 
  10. LEFT JOIN ' . $wpdb->term_relationships . ' tr2 ON tr1.object_id = tr2.object_id AND tr2.term_taxonomy_id IN(' . implode($pmpro_my_cats) . ')  
  11. WHERE tr1.term_taxonomy_id IN(${1}) AND tr2.term_taxonomy_id IS NULL ) ';  
  12. $where = preg_replace($pattern, $replacement, $where); 
  13.  
  14. //remove filter for next query 
  15. remove_action('posts_where', 'pmpro_posts_where_unhide_cats'); 
  16.  
  17. return $where;