author = 2 OR post_author IN (2).'/\b(?:' . $wpdb->posts . '\.)?post_author\s*(?:=|IN)\s*\(?(\d+)\)?/' $regex = '/\(?\b(?:' . $wpdb->posts . '\.)?post_author\s*(?:=|IN)\s*\(?(\d+)\)?/'; $where = preg_replace($regex, '(' . $maybe_both_query . ' ' . $terms_implode . ')', $where, -1); } // Allow users to edit orphan posts. if (current_user_can('ppma_edit_orphan_post')) { $where .= " OR (post_author = 0 && {$wpdb->posts}.post_type = 'post' && {$wpdb->posts}.post_status IN ('publish', 'private'))"; } return $where; } /** * Modify the JOIN clause on author queries. * * @param string $join Existing JOIN clause. * @param WP_Query $query Query object. * * @return string */ public static function filter_posts_join($join, $query) { global $wpdb; if ( ! $query->is_author() || empty($query->authors_having_terms)) { return $join; } // Check to see that JOIN hasn't already been added. Props michaelingp and nbaxley. $term_relationship_inner_join = " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $term_relationship_left_join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $term_taxonomy_join = " INNER JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id )"; // 4.6+ uses a LEFT JOIN for tax queries so we need to check for both. if (false === strpos($join, trim($term_relationship_inner_join)) && false === strpos($join, trim($term_relationship_left_join))) { $join .= $term_relationship_left_join; } if (false === strpos($join, trim($term_taxonomy_join))) { $join .= str_replace('INNER JOIN', 'LEFT JOIN', $term_taxonomy_join); } return $join; } /** * Modify the GROUP BY clause on author queries. * * @param string $groupby Existing GROUP BY clause. * @param WP_Query $query Query object. * * @return string */ public static function filter_posts_groupby($groupby, $query) { global $wpdb; if ( ! $query->is_author() || empty($query->authors_having_terms)) { return $groupby; } $having = 'MAX( IF ( ' . $wpdb->term_taxonomy . '.taxonomy = "author", IF ( ' . $query->authors_having_terms . ',2,1 ),0 ) ) <> 1 '; $groupby = $wpdb->posts . '.ID HAVING ' . $having; return $groupby; } } Home - Edugist Education News, Resources and Insights

Advertisement

Custom Module

Top Reviews

error: Content is protected !!