Closed srtfisher closed 2 years ago
why don't we want to modify the query if the post_status is set to any
? and more importantly, will any
include the archiveless status? reading my own code and not remembering it in-depth (😅), it seems like any
might not include it, so I was explicitly adding it 🤷
@mboynes this is more so for non-main queries. Before #39 this was using post_where and wasn't modifying non-main queries at all (see the old code here https://github.com/alleyinteractive/archiveless/blob/before-refactor/class-archiveless.php#L307-L317). Now we do need to modify almost every query unless they're for a specific post_status.
We totally don't need the secondary check for 'post status != archiveless', I removed that.
The root of my problem was trying to query for all posts (including archiveless posts) through a non-main query. I set the post_status = any
and I still didn't receive the expected posts. My mistake was assuming that excluding any
would fix it but it was just a red herring. The actual fix I needed to make was in get_default_post_statuses()
.
I was setting publicly_queryable
to true which core doesn't do. Once that was removed, my custom query included archiveless posts again.
I've added a few tests to help test all the various edge cases, too.
Coming back to this, I did walk back some of the previous changes made to this plugin. With #39 it would start including archiveless posts with any get_posts()
call. This breaking change presented some problems with existing usage of the archiveless plugin.
I updated this plugin to only ignore post_status
set to any
and not publish
. I also clarified the documentation https://github.com/alleyinteractive/archiveless/tree/post-status-any#handling-archiveless-posts-with-get_posts-calls to also call out that get_posts()
calls will not have archiveless posts in them by default.
Added some more tests as well.
any
is passed as thepost_status
that archiveless does not modify the query. The query should return archiveless posts normally then with an unmodified query.get_posts()
calls will not have archiveless posts returned by default. This logic in the plugin broke backward compatibility with some existing plugin use.