From bd647674ba5259d15d675a0246ce3b037b2e3be2 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 20 Dec 2024 08:48:21 +0100 Subject: [PATCH] Enable a /friends/tag/ page to see the friend posts tagged --- includes/class-friends.php | 29 +++++++++++++++++++++++++++++ includes/class-frontend.php | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/includes/class-friends.php b/includes/class-friends.php index d1babbdc..7486ae0a 100644 --- a/includes/class-friends.php +++ b/includes/class-friends.php @@ -1175,6 +1175,35 @@ function ( $post_format ) { return $tax_query; } + public function wp_query_get_post_tag_tax_query( $tax_query, $filter_by_post_tag ) { + if ( empty( $filter_by_post_tag ) ) { + return $tax_query; + } + + if ( ! is_array( $filter_by_post_tag ) ) { + $filter_by_post_tag = array( $filter_by_post_tag ); + } + + if ( ! empty( $tax_query ) ) { + $tax_query['relation'] = 'AND'; + } + $post_tag_query = array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'operator' => 'IN', + 'terms' => $filter_by_post_tag, + ); + + if ( ! empty( $tax_query ) ) { + $tax_query[] = $post_tag_query; + } else { + $tax_query = array( $post_tag_query ); + } + + return $tax_query; + } + + /** * Plural texts for post formats. * diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 2ea17458..17fc2be8 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -1409,6 +1409,11 @@ public function friend_posts_query( $query ) { } break; + case 'tag': + $post_tag = array_shift( $pagename_parts ); + $tax_query = $this->friends->wp_query_get_post_tag_tax_query( $tax_query, $post_tag ); + break; + default: // Maybe an author. $author = User::get_by_username( $current_part ); if ( false === $author || is_wp_error( $author ) ) {