WordPress: ottenere il numero complessivo di post di un determinato custom post type

WordPress: ottenere il numero complessivo di post di un determinato custom post type

In WordPress è semplice ottenere il numero complessivo di post appartenenti ad un determinato custom post type.

La soluzione è la seguente:


function my_get_cpt_count( $type = 'post' ) {
    global $wpdb;
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '$type' AND post_status = 'publish'" );
    return $count;
}

Torna su