get_posts - ottieni tutti i post per ID autore
Voglio ottenere tutti i post di un determinato ID autore (utente corrente). Successivamente, voglio selezionare il primo post creato da questo utente (ASC). Penso di non usare gli argomenti corretti in get_posts, è così? $current_user_posts contiene sempre un Array con tutti i post del blog in diversi oggetti WP_Post.
global $current_user;
get_currentuserinfo();
$args = array(
'author' => $current_user->ID, // Potrei anche usare $user_ID, giusto?
'orderby' => 'post_date',
'order' => 'ASC'
);
// ottieni i suoi post in ordine 'ASC'
$current_user_posts = get_posts( $args );

Sono un po' confuso. Se vuoi ottenere solo un elemento dall'array dei post puoi farlo così:
- reset($current_user_posts) - primo post
- end($current_user_posts) - ultimo post
Ma se vuoi ottenere un solo post con get_posts()
puoi usare l'argomento posts_per_page
per limitare i risultati.
$args = array(
'author' => $current_user->ID,
'orderby' => 'post_date',
'order' => 'ASC',
'posts_per_page' => 1
);
Maggiori informazioni sui parametri puoi trovarle nella pagina WP Query Class Reference (get_posts()
accetta gli stessi parametri di WP Query).

i tuoi $args funzionano bene ma non capisco la tua prima risposta. Come usare $current_user_posts. Potresti mostrarmelo?

Se vuoi stampare il titolo del primo post dovresti usare: echo $current_user_posts[0]['title']
. Il 'title' è la chiave per ciò che ti serve dall'array. La lista completa delle chiavi puoi ottenerla con print_r(array_keys($current_user_posts))
.
"Come usarlo" dipende da cosa vuoi farci.

@kindo, ti è stato utile? È questa la risposta di cui avevi bisogno?

$current_user_posts[0]['ID'] non funziona. ma la prima soluzione con l'aggiunta di 'numberposts' o 'posts_per_page' (usati in modo equivalente) funziona bene. grazie

@kindo, Scusa, ho dimenticato che get_posts()
restituisce un array di oggetti post. Usa $current_user_posts[0]->ID

global $current_user;
$args = array(
'author' => $current_user->ID,
'orderby' => 'post_date',
'order' => 'ASC',
'posts_per_page' => -1 // nessun limite
);
$current_user_posts = get_posts( $args );
$total = count($current_user_posts);
e semplicemente cicla i post dell'utente corrente

funziona con (wp4.9.7)
$user_id = get_current_user_id();
$args=array(
'post_type' => 'POSTTYPE',
'post_status' => 'publish',
'posts_per_page' => 1,
'author' => $user_id
);
$current_user_posts = get_posts( $args );
$total = count($current_user_posts);
wp_die( '<pre>' . $total . '</pre>' );
