wordpress/wp-content/plugins/cms-tree-page-view/functions.php
/**
 * Get number of posts from WPML
 */
Get number of posts from WPML
Get number of posts from WPML
function cms_tpv_get_wpml_post_counts($post_type) {
	global $wpdb;
	$arr_statuses = array("publish", "draft", "trash", "future", "private");
	$arr_counts = array();
	foreach ($arr_statuses as $post_status) {
		$extra_cond = "";
		if ($post_status){
			$extra_cond .= " AND post_status = '" . $post_status . "'";
		}
		if ($post_status != 'trash'){
			$extra_cond .= " AND post_status <> 'trash'";
		}
		$extra_cond .= " AND post_status <> 'auto-draft'";
		$sql = "
			SELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t
			JOIN {$wpdb->posts} p ON t.element_id=p.ID
			JOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1
			WHERE p.post_type='{$post_type}' AND t.element_type='post_{$post_type}' {$extra_cond}
			GROUP BY language_code
		";
		$res = $wpdb->get_results($sql);
		$langs = array();
		$langs['all'] = 0;
		foreach($res as $r) {
			$langs[$r->language_code] = $r->c;
			$langs['all'] += $r->c;
		}
		$arr_counts[$post_status] = $langs;
	}
	return $arr_counts;
}
function cms_tpv_get_wpml_post_counts ( $ post_type ) { global $ wpdb ; $ arr_statuses = array ( " publish " , " draft " , " trash " , " future " , " private " ) ; $ arr_counts = array ( ) ; foreach ( $ arr_statuses as $ post_status ) { $ extra_cond = " " ; if ( $ post_status ) { $ extra_cond .= "  AND post_status = ' " . $ post_status . " ' " ; } if ( $ post_status != 'trash' ) { $ extra_cond .= "  AND post_status <> 'trash' " ; } $ extra_cond .= "  AND post_status <> 'auto-draft' " ; $ sql = " 
			SELECT language_code, COUNT(p.ID) AS c FROM  { $ wpdb -> prefix } icl_translations t
			JOIN  { $ wpdb -> posts }  p ON t.element_id=p.ID
			JOIN  { $ wpdb -> prefix } icl_languages l ON t.language_code=l.code AND l.active = 1
			WHERE p.post_type=' { $ post_type } ' AND t.element_type='post_ { $ post_type } '  { $ extra_cond } 
			GROUP BY language_code
		 " ; $ res = $ wpdb -> get_results ( $ sql ) ; $ langs = array ( ) ; $ langs [ 'all' ] = 0 ; foreach ( $ res as $ r ) { $ langs [ $ r -> language_code ] = $ r -> c ; $ langs [ 'all' ] += $ r -> c ; } $ arr_counts [ $ post_status ] = $ langs ; } return $ arr_counts ; }
Get number of posts from WPML
Get number of posts from WPML