I noticed that draft posts are available for selection in the Relationship field and I’m wondering if these should be filtered out by default – or perhaps a toggle could be added to the Relationship field to select allowed post statuses (published, draft, private)?
In the absence of a UI for toggling the allowed statuses, rather than using a hook to filter out draft posts, the hook could be used to include them if there was a need for it.
I can see the value of including draft posts: allowing you set up the relationship in advance of publishing said posts or pages. At the same time my gut reaction was that this could introduce additional margin for error for the client/user who is editing the site and also clutters up the UI in cases where the client is averse to clearing out old unpublished posts.
This may not help, just a why does this happen.
When performing a query on the posts ACF does not set a value for post_status. This results in WP using the default value as described here https://developer.wordpress.org/reference/classes/wp_query/#status-parameters.
So basically when you’re logged into the admin you get everything other than “trash”, “inherit” and “auto-draft” statuses.
This differs from the front end as the default there is only “publish” and any custom statuses that have been set up as public.
As far as a change in the way ACF does this, you should contact the developer here https://www.advancedcustomfields.com/contact/
That makes sense! Thanks John.
I’m now wondering if I were to select a draft post when I retrieve the field on the front end will that draft post be included? The main thing that I would worry about is accidentally displaying draft posts on the front end that should not be public
Going to test this today
Because of the default, no. ACF does not set the post_status either, only the “post__in” argument to WP_Query. So WP applies the default of “publish” unless the user is logged in and then it also includes “private”
Good to know! Thanks
I could see this potentially causing some confusion for less savvy users editing a relationship field if they were to select only draft posts (as no posts would appear on the front end)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We are receiving some fantastic feedback on ACF PRO 5.9 beta - thank you 🎉.— Advanced Custom Fields (@wp_acf) June 25, 2020
Beta 3 is almost ready and comes with an updated “duplicate” icon design for the Flexible Content field made from pseudo-elements.
What do you think? pic.twitter.com/UvxbtlKYDZ
© 2020 Advanced Custom Fields. Subscribe