Skip to main content
Commonmark migration
Source Link

Another approach could be to use a function that loops through [get_posts][1]get_posts and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts

Another approach could be to use a function that loops through [get_posts][1] and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts

Another approach could be to use a function that loops through get_posts and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>.

replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

Another approach could be to use a function that loops through [get_posts][1] and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts

Another approach could be to use a function that loops through [get_posts][1] and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts

Another approach could be to use a function that loops through [get_posts][1] and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts

Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

Another approach could be to use a function that loops through [get_posts][1] and prints the result.

Check this Q&A: When should you use WP_Query vs query_posts() vs get_posts()?

// function located in the theme's functions.php
function wpse_78117_print_authors_last_post() 
{
    $user_ids = array( '1', '2' );
    foreach( $user_ids as $user )
    {
        $args = array( 
                'post_type'     => 'post',
                'numberposts'   => 1,
                'author'        => $user
            ); 
        
        // as we are getting only 1 post, extract it from the returned array
        $user_post = array_shift( get_posts( $args ) );
        
        // similar
        $nick = array_shift( get_user_meta( $user, 'nickname' ) );

        // custom output, $user_post contains all the post normal data
        echo $user_post->post_title . ', by: ' . $nick;
    }
}

And then use it in any theme template:
<?php wpse_78117_print_authors_last_post(); ?>. [1]: http://codex.wordpress.org/Template_Tags/get_posts