Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
I want to display sticky posts in a second language or fallback to the default language with a custom query.
Solution:
1. Go to WPML > Settings > Post Types Translation > Set Posts preference to "Translatable - use translation if available or fallback to default language:
2. Use the argument below for the custom query:

$test_ids = unserialize($wpdb->get_var( "SELECT `option_value`, `option_id` FROM `$wpdb->options` WHERE `option_name` = 'sticky_posts'" ));
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'post__in' => $test_ids,
);

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 3 replies, has 2 voices.

Last updated by vanessaS-12 1 year, 4 months ago.

Assisted by: Long Nguyen.

Author Posts
July 11, 2023 at 6:34 am #14010171

vanessaS-12

hello! i have an issue on our website, nextcloud.com. basically I have a custom wp query which does include the option 'post__in' => get_option( 'sticky_posts' ) to get only the sticky posts. It works fine on English, which is default language, but on other languages like french, there are shown only the translation of those sticky posts that are translated

July 11, 2023 at 7:57 am #14011029

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Here is the ticket. I'm asking our 2nd tier support about this issue and update you here when I have something to share.

Thanks.

July 11, 2023 at 9:12 am #14012103

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I got some information from our 2nd tier support. You can use the code below to get the sticky posts and display them on the translation page.

$test_ids = unserialize($wpdb->get_var( "SELECT `option_value`, `option_id` FROM `$wpdb->options` WHERE `option_name` = 'sticky_posts'" ));
$args = array(
	'post_type' => 'post',
	'post_status' => 'publish',
	'post__in' => $test_ids,
);

Let me know how it goes.