// Shortcode [lo_mas_visto] — lista los posts más visitados
add_shortcode('lo_mas_visto', function($atts){
$atts = shortcode_atts(['limit'=>5], $atts);
$q = new WP_Query([
'post_type' => 'post',
'posts_per_page' => intval($atts['limit']),
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
]);
ob_start();
if ($q->have_posts()){
echo '
';
wp_reset_postdata();
} else {
echo 'No hay artículos vistos aún.
';
}
return ob_get_clean();
});