Hi! When I am trying to connect an existing related post (for example, type = feature) from a post edit screen (for example, type = location), all features matching my query show as options in the dropdown as I type the name. I would like to instead have only published features show as options, not features in draft or review status. The use case is being able to save unpublished feature posts (something like "October reading list") to reuse in the future without having them clutter up the dropdown when I'm trying to add a currently published feature to a location. Is this possible?
Hello,
Yes, this is possible with a small filter. By default, "Connect existing" lists published, draft, pending and scheduled posts. Types has a filter to change which statuses are offered.
Please add this code to your theme's functions.php file, or as a new snippet in Toolset > Settings > Custom Code:
add_filter( 'types_force_post_status_in_post_relationship_by_slug_location-feature', function ( $post_status, $role ) {
return array( 'publish' );
}, 10, 2 );
Replace "location-feature" with the slug of your relationship. You can find it in Toolset > Relationships: edit the relationship and check the "Relationship slug" field.
After that, when you click "Connect existing Feature" on a Location, only published Features will show in the dropdown. Your draft and pending Features stay saved and are not changed.
If you want this for all relationships on the site, use this filter instead:
add_filter( 'types_force_post_status_in_related_post', function ( $post_status ) {
return array( 'publish' );
} );
For more information:
The custom code suggested above is not part of our official support policy. We will not be able to maintain or guarantee that it will work. It is an attempt to help you understand what should be done for scenarios where the built-in Toolset features are not there to handle your request.