Due to the large volume of support requests you may experience longer wait until a supporter handles your request. We apologize for the inconvenience this causes. We encourage you to please search the forum for other support topics that may be helpful and to review our documentation. A supporter will respond to you as soon as possible.

[Closed] get_posts() shows all languages

Home Support English Support [Closed] get_posts() shows all languages

This topic contains 9 replies, has 2 voices, and was last updated by  Daniel Dvorkin 2 years, 11 months ago.

Author Posts
Author Posts
October 10, 2011 at 6:47 pm #37768

Markos

I'm using the function get_posts(); to show my custom type posts.
get_pages() doesn't seem to work with post types anymore.
Here's my code:

$mypages = get_posts( 'post_type=intro');
foreach( $mypages as $page ) {
        echo $page->post_title;
}

This brings me the titles from all languages.

October 10, 2011 at 6:57 pm #37770

Markos

After looking around here I fixed this problem by adding

'suppress_filters' => 0

.
Now my problem is the custom meta which won't show up in my secondary language.
Here's my code:

echo get_post_meta(icl_object_id($page->ID, 'post', true, 'en'), "the_name", true);
October 10, 2011 at 9:36 pm #37771

Daniel Dvorkin

You can configure WPML to automatically copy that meta to the translated post (in WPML->Translation Management->Multilingual content setup)

October 10, 2011 at 9:50 pm #37772

Markos

That would be an option but I don't want to have duplicated meta.
This used to work well with the previous versions. When I try do the same with

get_post_thumbnail

it works, but not with the meta.

October 10, 2011 at 9:50 pm #37773

Daniel Dvorkin

icl_object_id($page->ID, 'post', true, 'en') is returning the correct id?

October 10, 2011 at 10:15 pm #37774

Markos

Yes, but on false it doesn't return anything.
My languages are 'en' & 'zh-hans'
this

icl_object_id($page->ID, 'post', false, 'en')

returns nothing on both languages.
While this

icl_object_id($page->ID, 'post', true, 'en')

returns the IDs of each languages.

October 10, 2011 at 10:16 pm #37775

Daniel Dvorkin

oh, sorry, i missed it! you are quering for "post" and I see your type is "intro". Replace it in the second parameter.

October 10, 2011 at 10:20 pm #37776

Markos

Like this?

$o_ID = icl_object_id($page->ID, 'intro', false, 'en');

This returns nothing. I don't know what has changed or what I'm doing wrong because this used to work.

October 11, 2011 at 9:08 am #37777

Markos

Tested on a new install, I think the problem comes from Yoast SEO Plugin.
Without it, I'm able to use get_pages() for custom type posts and the meta show up correct.

October 11, 2011 at 11:46 am #37778

Daniel Dvorkin

uhm. Weird. Are you using the last version of Yoast SEO?

The topic ‘[Closed] get_posts() shows all languages’ is closed to new replies.