Skip to content

Instantly share code, notes, and snippets.

@MarceloGlez
Created November 28, 2022 22:57
Show Gist options
  • Save MarceloGlez/48d6ce29f1a102e109e0eea5986bd964 to your computer and use it in GitHub Desktop.
Save MarceloGlez/48d6ce29f1a102e109e0eea5986bd964 to your computer and use it in GitHub Desktop.
Crea un shortcode para mostrar cantidad de post de un CPT en Wordpress
/* Muestra el total de posts de un CPT - reemplaza ('cpt'), usar shortcode: [cantidad_cpt] */
function shortcode_total_cpt($atts) {
return wp_count_posts('cpt')->publish;
}
add_shortcode('cantidad_cpt', 'shortcode_total_cpt');
/* Muestra el total de posts del blog genérico, usar shortcode [cantidad_post] */
function shortcode_total_post($atts) {
return wp_count_posts('post')->publish;
}
add_shortcode('cantidad_post', 'shortcode_total_post');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment