Last active
April 20, 2024 02:47
-
-
Save joshuadavidnelson/4f5e51354601234130cf2323f74632bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the post search arguments allow for cross-post-type connections in MultilingualPress. | |
* | |
* MultilingualPress (MLP) connects translated posts and pages, but by default doesn't connection across post types. | |
* This changes that behavior by allowing other post types to be chosen in the interface. No other modifications are | |
* needed to achieve this, because MLP uses the post_id and doesn't care about post_type outside of the search query. | |
* | |
* @param array $args the WP_Term_Query arguments used. | |
* @return array | |
*/ | |
add_filter( 'multilingualpress.remote_post_search_arguments', function( $args ) { | |
// Change this array to the post types you want to connect. | |
$translated_post_types = array( 'post', 'page', 'product' ); | |
// Make sure we have a valid $args['post_type'] value | |
// and that we aren't removing the current post type. | |
if ( isset( $args['post_type'] ) | |
&& is_string( $args['post_type'] ) | |
&& in_array( $args['post_type'], $translated_post_types, true ) ) { | |
$args['post_type'] = $translated_post_types; | |
} | |
return $args; | |
}, 100, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment