Skip Navigation

[Waiting for user feedback] Only show published items when choosing related post

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by - 3 days, 23 hours ago.

Assisted by: Christopher Amirian.

Author
Posts
#2913768

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?

#2915244

Christopher Amirian
Supporter

Languages: English (English )

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.