Created
January 24, 2020 09:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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