soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
315 stars 30 forks source link

Empty archive loads the catch-all template #1866

Open Merionis opened 3 years ago

Merionis commented 3 years ago

Describe the bug An archive for a custom post_type, which functions normally, will not display if it has no content, for example for search featuring a keyword not matching any result.

Have you tried all the steps at https://oxygenbuilder.com/documentation/troubleshooting/troubleshooting-guide/? Yes

Are you able to replicate the issue on a Sandbox install at https://oxygenbuilder.com/try? Yes Here is the link to my woocommerce products archive: http://naughty-cowfish.w6.wpsandbox.pro/shop/ Here is my search with a matching keyword: http://naughty-cowfish.w6.wpsandbox.pro/shop?s=test Here is my search for a non-matching keyword: http://naughty-cowfish.w6.wpsandbox.pro/shop?s=abc

To Reproduce Steps to reproduce the behavior:

setup steps

  1. The default "post" wordpress post_type somehow isn't affected by this, you'll need a plugin with a custom post_type, such as woocommerce (which I picked because it's well built, extremely popular, and won't be the reason behind any breakage)
  2. create a few of those posts for test purposes
  3. Create a default catch-all template and an archive template
  4. Have a listing of your post-type in your archive, such as the "Easy Posts" block
  5. Create a page and assign it as your archive. For woocommerce it's done automatically as the "Shop" page.
  6. Assign the archive template to your archive page.

bug testing steps

  1. Search for a non-result yielding keyword, and the archive page & template will be dismissedand the default "catch-all" template will be loaded.

Expected behavior An empty research should load the archive template.

What actually happens The catch-all template is loaded instead of the designated archive.

Screenshots

Desktop (please complete the following information): 78.0.2 (64-bit) for Ubuntu

Smartphone (please complete the following information):

Additional context This problem happens on an e-commerce website where the shop's design differs from the rest of the website, and also we have not set a "catch-all" page so we just get a blank page in that situation. We also work with multiple custom post_types with each their design, and a single catch-all simply won't do.

I thought the blank page was a bug so I investigated, and found this:

In oxygen/component-framework/includes/templates.php, on line 443, the post_type is gathered using "get_post_type", which uses the global $post to get its post_type. Given that we have no results for the query, the global $post is empty and so it doesn't enter the following condition which returns the proper archive template. It can easily be fixed by replacing the line 443: $post_type = get_post_type(); With this line: $post_type = get_queried_object()->name

I think a new option on the block "Easy posts" should be added for empty results as the only way to handle such results with the proposed edits would be a custom code block.

jpedigo commented 3 years ago

That last comment is my bug report from 2 years ago. Two people have provided the fix - a single line of code - and this is still outstanding. Come on, guys, this is pathetic.