Advertisement
Guest User

Untitled

a guest
Jan 15th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. /**
  2.      * Modify the author query posts SQL to include posts co-authored
  3.      */
  4.     function posts_join_filter($join, $query) {
  5.         global $wpdb;
  6.  
  7.         if ($query->is_author()) {
  8.  
  9.             if (!empty($query->query_vars['post_type']) && !is_object_in_taxonomy(
  10.                 $query->query_vars['post_type'], $this->coauthor_taxonomy
  11.             )
  12.             )
  13.                 return $join;
  14.  
  15.             // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley
  16.             $term_relationship_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
  17.             $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )";
  18.  
  19.             if ($join) {
  20.                 if (strpos($join, trim($term_relationship_join)) === false) {
  21.                     $join .= str_replace("INNER JOIN", "LEFT JOIN", $term_relationship_join);
  22.                 }
  23.                 if (strpos($join, trim($term_taxonomy_join)) === false) {
  24.                     $join .= str_replace("INNER JOIN", "LEFT JOIN", $term_taxonomy_join);
  25.                 }
  26.             } else {
  27.                 $join = $term_relationship_join . $term_taxonomy_join;
  28.             }
  29.         }
  30.  
  31.         return $join;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement