Automattic / newspack-blocks

Gutenberg blocks for the Newspack project.
207 stars 43 forks source link

fix: also search for coauthor posts by term slug #1954

Closed leogermani closed 1 week ago

leogermani commented 2 weeks ago

All Submissions:

Changes proposed in this Pull Request:

When searching for posts from an author that is a WP User (not a guest author), we should also (actually maybe only) search by term slug.

This PR adds a few extra conditions to make sure we find posts by an author when searching by terms.

The specific case we are fixing here is from users that ended up with their Display Name as the term name, and thus the search term name using the user_login as input would never find anything. We also need to search by user_nicename and make sure we search in the slug field.

How to test the changes in this Pull Request:

  1. Activate CoAuthors Plus
  2. Create a user and assign a few posts to it
  3. Create a post and assign this user as a secondary co-author (a co-author, but not the author on the post_author field in the database
  4. On a page, add a Home Page posts block and filter by this author
  5. Make sure all the posts show up, including the one they are not the main author (on trunk it won't show up)
  6. Add this somewhere:
// Disable guest authors before CoAuthors plus is initialized
add_action(
    'init',
    function() {
        add_filter( 'coauthors_guest_authors_enabled', '__return_false' );
    },
    9
);
  1. Make sure the block still fetch the correct posts.
  2. Remove the snippet to re-enable Guest Authors
  3. Create a guest author
  4. Create a post and assign only the guest author to it.
  5. You can confirm and see that the post_author field in the DB still points to your admin
  6. In the HPP block, filter posts by the guest author and confirm it works
  7. Now filter posts by your admin, and confirm the post by the guest author is NOT returned

Other information:

github-actions[bot] commented 1 week ago

Hey @leogermani, good job getting this PR merged! :tada:

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! :heart: