Skip to content

Commit

Permalink
Enable a /friends/tag/ page to see the friend posts tagged
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 20, 2024
1 parent e152be2 commit bd64767
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions includes/class-friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit bd64767

Please sign in to comment.