Skip to content

Instantly share code, notes, and snippets.

@AndreaBarghigiani
Created January 24, 2020 09:18
Show Gist options
  • Save AndreaBarghigiani/db1bc58e2f8965584fd2976fd6382497 to your computer and use it in GitHub Desktop.
Save AndreaBarghigiani/db1bc58e2f8965584fd2976fd6382497 to your computer and use it in GitHub Desktop.
Recuperare una lista di autori WordPress con shortcode o con Hook. Impara a sviluppare con WordPress su: https://skillsandmore.org
<?php
// Aggiungo la lista autori agganciandomi a un Hook
add_action( 'il_tuo_hook', 'sam_recupero_autori' );
function sam_recupero_autori() {
$args = [
'role' => 'author',
'fields' => 'ID'
];
$users_list = get_users( $args );
echo '<div class="lista-autori">';
foreach ( $users_list as $user_id ) {
$nome = get_the_author_meta( 'display_name', $user_id );
$bio = get_the_author_meta( 'description', $user_id );
echo '<div class="autore">';
echo '<h3>' . esc_html( $nome ) . '</h3>';
echo '<p>' . esc_html( $bio ) . '</p>';
echo '</div>';
}
echo '</div>';
}
<?php
add_shortcode( 'sam_mostra_autori', 'sam_recupero_autori' );
function sam_recupero_autori() {
$args = [
'role' => 'author',
'fields' => 'ID'
];
$users_list = get_users( $args );
echo '<div class="lista-autori">';
foreach ( $users_list as $user_id ) {
$nome = get_the_author_meta( 'display_name', $user_id );
$bio = get_the_author_meta( 'description', $user_id );
echo '<div class="autore">';
echo '<h3>' . esc_html( $nome ) . '</h3>';
echo '<p>' . esc_html( $bio ) . '</p>';
echo '</div>';
}
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment