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.

Our next available supporter will start replying to tickets in about 1.34 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by ghledisC 1 year ago.

Author Posts
April 24, 2023 at 8:31 am #13525261

ghledisC

I am trying to get only the source language posts on a secondary language page

I have been trying to use

do_action( 'wpml_switch_language', string 'en' );

$sitepress->switch_lang('en');

change the 'suppress_filters' option in get_posts args (This gives me all languages, but I want only source i.e english).

I basically want to make a shortcode that get's all english posts and counts them and displays the number. But I need to be able to get the English posts no matter what language is currently set on the page.

April 24, 2023 at 11:33 am #13526559

Andreas

Hi,

before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.

You code seems not correct to me.

You can query the posts in the original language and get the ID( with WordPress Hooks ) , then you can use this hook :

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

And feed it with the ID you got from the previous step and the above hook will return the IDs from a specific language.

Use it in a loop and you can get the number you wish.

Wrap the whole function into a shortcode and use it with whatever you ish.

Have in mind that giving support is out of the scope of this forum but the hints I have shared are a very good starting point in order to build whatever you wish.

If you are not able to accomplish this, you could also try to hire a WPML contractor (https://wpml.org/contractors/)

Regards,
Andreas

April 24, 2023 at 11:52 am #13526843

ghledisC

Instead of get_posts I used WP_query with a pre_get_posts hook to switch the language, and this worked.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.