Overview
Include posts with extra statuses in Relationship, Post Object, and Page Link field searches, where each is still checked.
Description
When a logged-in user searches in a Relationship, Post Object, or Page Link field, ACF leaves out other users’ posts with statuses the user can’t normally read, such as drafts, pending, scheduled, and private posts.
Use this filter when your site grants access to individual posts, such as through a membership or editorial plugin, a map_meta_cap callback, or the acf/user_can_read_post filter. Statuses removed from the list are included in the search query, and each post is then checked to see whether the user can read it, so posts they can’t read are still left out.
WordPress hides other users’ private posts itself, so removing private from the list doesn’t include them.
Parameters
apply_filters( 'acf/fields/relational/unreadable_post_statuses', $statuses, $post_type );
$statuses
(string[]) The statuses of other users’ posts hidden from the current user.
$post_type
(string) The post type being searched.
Example
Include drafts in searches for a post type
// Pair with a map_meta_cap callback or the acf/user_can_read_post filter that
// lets the user read these drafts. Otherwise they're still left out.
add_filter( 'acf/fields/relational/unreadable_post_statuses', function ( $statuses, $post_type ) {
if ( 'lesson' === $post_type ) {
$statuses = array_diff( $statuses, array( 'draft' ) );
}
return $statuses;
}, 10, 2 );
Changelog
- Added in version 6.8.11
Notes
- Because each post is checked after the query runs, a page of search results may contain fewer posts than usual, or none. Loading more results still continues to the next page.
- This filter only affects searches. To change whether a user can read a post, use the
acf/user_can_read_postfilter. - This filter doesn’t run for visitors who aren’t logged in. Their search results are still checked post by post, so
acf/user_can_read_postalone decides which posts they see. - Other users’ posts of non-public post types are left out of searches before this filter applies, unless the field’s “Filter by Post Type” setting includes the post type. This filter can’t include them.
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.
Related
- Filters: acf/user_can_read_post
- Filters: acf/fields/relational/hide_unreadable_posts
- Field Types: Relationship
- Filters: acf/bidirectional/can_update_target
- Filters: acf/fields/allow_append_choices