Skip to content

Conversation

@draganescu
Copy link
Contributor

@draganescu draganescu commented Apr 27, 2022

What?

Fixes #40431

Why?

When building author archive templates the author block should still render even if there are no posts.

How?

If there is no context we default to trying to get the author from the global query.

Testing Instructions

  1. Open Site Editor.
  2. Navigate to the Templates List.
  3. Click "Add" and add in an author template.
  4. Add a Post Author block at the top of the template.
  5. Add a Query Loop below it with the option of “Inherit query from template” selected.
  6. Publish the template.
  7. View an author with posts and see the author name.
  8. View an author without posts and notice the author still shows

Notes

  • Is it a better fix to make the default context come from the global wp query?

@draganescu draganescu requested a review from ajitbohra as a code owner April 27, 2022 11:02
@draganescu draganescu added [Type] Bug An existing feature does not function as intended [Block] Post Author Affects the Post Author Block Needs Technical Feedback Needs testing from a developer perspective. labels Apr 27, 2022
@draganescu draganescu changed the title Inherit autheor from global query Inherit author from global query Apr 27, 2022
@draganescu draganescu requested review from aristath and ntsekouras and removed request for ajitbohra May 27, 2022 14:35
Co-authored-by: George Mamadashvili <[email protected]>
@draganescu
Copy link
Contributor Author

@Mamaduka Great suggestion! We do all these guards in post template or query no results as well. Why? get_query_var assumes there always is a global $wp_query so this line if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) in both

  • packages/block-library/src/post-template/index.php, and
  • packages/block-library/src/query-no-results/index.php

could go away?

@Mamaduka
Copy link
Member

@draganescu, we need all the global arguments to build an inherit query in both cases. Maybe we should propose get_query_vars() function for getting all the arguments.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works as expected. Thanks, @draganescu!

@draganescu draganescu merged commit 7a68774 into trunk May 31, 2022
@draganescu draganescu deleted the try/fix-author-block-no-posts branch May 31, 2022 08:39
@github-actions github-actions bot added this to the Gutenberg 13.4 milestone May 31, 2022
youknowriad pushed a commit that referenced this pull request Jun 3, 2022
* inherit autheor from global query

* remove useless merge with block query args since there are none

* lint PHP

* Simplify getting author from query vars

Co-authored-by: George Mamadashvili <[email protected]>

Co-authored-by: George Mamadashvili <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Post Author Affects the Post Author Block Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post Author Block doesn't display when author has no posts

4 participants