Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 18 replies, has 2 voices.

Last updated by Andrey 1 year, 6 months ago.

Assisted by: Andrey.

Author Posts
July 5, 2023 at 10:20 am #13948791

mykolaK-6

Andrey, could you clarify how to get the language of the post given the $post_id?

July 5, 2023 at 8:59 pm #13954085

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Please use this filter to get the ID in the current language or in another language `wpml_object_id`

https://wpml.org/wpml-hook/wpml_object_id/

Or retrieve language information of a post by its ID `wpml_post_language_details`

https://wpml.org/wpml-hook/wpml_post_language_details/

July 7, 2023 at 3:01 pm #13969021

mykolaK-6

Hello Andrey!

Please see below my solution. It's not ideal, because it breaks pagination a bit, but it's feasible for our use case, as we don't have too many new post activities.

// Filter the activity feed by the language:
// 1. buffer the activity entry output...
add_action('bp_before_activity_entry', function () {
	ob_start();
});
// 2. clean the output if the activity is the post activity and languages don't match,
//    flush otherwise.
add_action('bp_after_activity_entry', function () {
	$get_lang = $_GET['lang'];
	$language_code = get_activity_post_language_code();
	if ( $language_code && $get_lang && $language_code !== $get_lang ) {
		ob_end_clean();
	} else {
		ob_end_flush();
	}
});

function get_activity_post_language_code() {
	if ( ! bp_get_activity_secondary_item_id() ) {
		return false;
	}

	$language_details = apply_filters( 'wpml_post_language_details', NULL, bp_get_activity_secondary_item_id() );
	if ( ! $language_details ) {
		return false;
	}

	return $language_details['language_code'];
}
July 10, 2023 at 2:41 pm #14007199

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for your feedback! Wow! That's great! I will report it further.

Have a lovely week!