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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 - - 9:00 – 18:00
- - - - - - -

Supporter timezone: Asia/Yerevan (GMT+04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christopher Amirian 1 year, 11 months ago.

Assisted by: Christopher Amirian.

Author Posts
May 27, 2022 at 10:33 am #11325109

davidM-25

Tell us what you are trying to do?
Hi, I want to display a post count on this page (under each user). And now it counts all posts (post types "post", "definition (lexique)", "tools") for both languages.
hidden link

Is there a way to count posts only for current language ?

I user count_user_posts to count posts by user.

$posts = count_user_posts($user->ID, $post_type = "post", $public_only = true);

I see there is a ticket where you resolver similar issue, but I cannot figure out how to use it https://wpml.org/forums/topic/count-post-per-language/

I have already did this steps, but that didn't help.
- Clear the Cache in WPML
- Remove ghost entries from the translation tables
- Fix element_type collation
- Fix WPML table collation
- Set language information
- Fix Terms count

Thanks in advance.

Best,
Alex

May 30, 2022 at 11:26 am #11342935

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

WPML does not support the count_user_posts function.

That is why you need to do the counting manually.

According to the reply below:

https://wpml.org/forums/topic/count-post-per-language/#post-10423833

You will need to select a language, loop over the posts, and store the result.
Then change the language, and do the same and count.
Do it for all the posts.
Switch back the language to the language that you had originally.

The code given in the response is as it and if you need additional help you will need to contact a qualified developer:

https://wpml.org/contractors/

Thanks.

The topic ‘[Closed] post count when displaying categories and post types’ is closed to new replies.