Query Loop Block UX bug? No warning or other indication that query loop block still has a filter for a deleted category
I had some Query Loop Blocks that had a category filter configured. Let’s say they were set to filter on category “CatOne”. This was working fine and the correct posts were showing (the ones from the CatOne category). Then, I decided that I didn’t want to use the CatOne category anymore. I changed the posts in that category to a different category and saved them. Then I deleted CatOne from my WordPress site. However, I didn’t update the Query Loop Blocks. (I simply forgot) After deleting CatOne the Query Loop Blocks were not showing any posts anymore (which I understand is the "correct" behavior as the filter is still in the block's filter settings). However, when editing these query loop blocks nothing would show in the “Categories” filter. So the edit screen was saying that there was no longer a filter on any category but it was not showing any posts anymore. It was as if the filter was still there in the database (underwater) but not showing anymore in the edit screen because the category had been deleted from the site.
I ended up solving it as follows: I created again CatOne with the same name and slug as before. Then edited the Query Loop Blocks, and added back the CatOne filter, saved, then removed again the CatOne filter, and saved again. At that point the Query Loop Blocks were showing posts again. Then I deleted once again the CatOne category from the site, and this time it didn’t result in issues. Later I was explained that it probably could have been solved by simply choosing a different category in the categories filter (and then removing it again afterwards), so the step of temporarily re-creating the deleted category may not have been necessary.
Nevertheless, this seems a UX bug? There should be some warning or indication/option in relation to the filter (that is still active) concerning the already deleted category? Otherwise, it's simply not possible to see in the edit screen what the issue is with the block, as it makes it appear as there is no filter active.
Thanks for reporting @GoldenGoldy!
Indeed in the editor we check for non existing ids and not show them in the UI, making this confusing and difficult to remove. The workaround you found does the trick but this should be handled better.
One way to go here could be to update the query as well, but this would result in a dirty state. Also we could potentially check server side and not apply such values in the Query. Would that be the expected result though? For example in your case that you had a Query filtered with a category, now that you deleted it did you expect to see a Query with all posts?
In general we have similar handling for other filters with ids like author etc.., so the solution we'll end up, will apply to all these cases.
Hi @ntsekouras , thanks for getting back to me!
In response to your question:
For example in your case that you had a Query filtered with a category, now that you deleted it did you expect to see a Query with all posts?
To be honest, that was my initial thought/expectation. However, later when I gave it some thought, I realized it might lead to undesired results in some cases? Let's say you'd delete a category and didn't realize you were still showing lists of posts filtered by this category on your website. If deleting the category would result in those lists simply showing all posts then you might get very weird results on the website? (for example, "here are our articles about XXX" followed by a list of articles about anything your website writes about, instead of just about XXX)
It might then be better to keep the query filtered by the now non-existing category ID, which then simply produces no results anymore as there simply can't be any posts in a category that no longer exists. However, then in the edit screen make it somehow visible that there is an existing filter on a category that no longer exists with the option to remove such category from the filter? Or perhaps even more solid, but potentially difficult to achieve?, would be to simply not allow a user to delete a category in case there are still filters that are using it? And then direct the user to either first update those filters, or give their approval for automatically updating them. (but maybe that is making it very complicated and in case of manually updating them it might become cumbersome if you have a lot of them)
In the situation where the query was showing posts of multiple categories, while only one of those categories was deleted, I guess it's straightforward that the query should continue to show the posts of only the remaining categories from the filter, which I believe is exactly what happens anyway. In that case automatically deleting the deleted category from the filter would not have any harmful effect I suppose.
Having a similar issue, but probably different:
WP Query block creates only an empty div to the actual published page, even though it displays the post listing correctly on the editing page:
<div class="wp-block-query is-layout-flow wp-block-query-is-layout-flow"></div>
Also, the article listing block won't work in other pages either. Some categories were removed recently, but I'm pretty sure the query block did not have a category filter on.
Deleting & re-creating the query block won't fix the problem. Tried switching theme, did not help. Other content on page display as it should. No errors in console. WP debug on and no PHP errors visible. There are published articles and like I said, it displays correctly in the editing view. Tried to re-create problem on another site unsuccessfully.
Is this the same issue or a different one? Any hints?