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.

This topic contains 1 reply, has 2 voices.

Last updated by Yvette 4 months, 1 week ago.

Assigned support staff: Yvette.

Author Posts
May 6, 2020 at 9:15 am #6068359



Im numbering my custom post type "Playlists" with the function below.

It was working while my site was only in french. However, it is not working anymore because it is quering all posts and not only the one in my main language (fr). $count is jumping 2 numbers when there is a translation so numbering is now erratic.

How could I Improve this to $count++ only for the post in the main language (fr) ?

Thanks for your help and suggestions

function updateNumbers() {
    /* numbering the published posts, starting with 1 for oldest;
    / creates and updates custom field 'incr_number';
    / to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_number',true); ?>
    / alchymyth 2010 */
    global $wpdb;
    $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'playlist' ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    $counts = 0 ;
    if ($pageposts):
        foreach ($pageposts as $post):
            add_post_meta($post->ID, 'incr_number', $counts, true);
            update_post_meta($post->ID, 'incr_number', $counts);
May 10, 2020 at 6:35 pm #6099211


Languages: English (English ) Spanish (Español )

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


Our support for custom coding is limited. But would it help to be able to just get the posts in one language?

In this case, you could try using a WP_Query

include the

'suppress_filters' => false 


Here´s an example:

And here is another approach using the pre_get_posts hook

The important thing is to set the supress_filters query argument to false and use the nomal WP query funcions that our filters hook into.

Does this help?

The topic ‘[Closed] Get only main language SELECT query’ is closed to new replies.