Created
February 25, 2023 19:56
-
-
Save airarm/ef79bfe9e85b08c58a7e3b91fe06b179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _wpml_posts_sql_query($post_type = 'post', $post_status = 'publish', $language_code = ICL_LANGUAGE_CODE) | |
{ | |
global $wpdb; | |
$post_type = "post_$post_type"; | |
$query = "SELECT COUNT( {$wpdb->prefix}posts.ID ) | |
FROM {$wpdb->prefix}posts | |
LEFT JOIN {$wpdb->prefix}icl_translations ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}icl_translations.element_id | |
WHERE {$wpdb->prefix}icl_translations.language_code = '{$language_code}' | |
AND {$wpdb->prefix}icl_translations.element_type = 'post_{$post_type}' | |
AND {$wpdb->prefix}posts.post_status = '$post_status'"; | |
return $query; | |
} | |
function wpml_count_posts($post_type = 'post', $post_status = 'publish', $language_code = ICL_LANGUAGE_CODE) | |
{ | |
global $wpdb; | |
return $wpdb->get_var( _wpml_posts_sql_query($post_type, $post_status, $language_code) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment