How can I list all WordPress users, their email adress, post title and post status?

I am looking for a way to return something like the following:

  • User, email, post title, post status
  • User, email, post title, post status
  • repeated….

Each user on my site has only 1 post. It is a custom post type called Company Listing.

Related posts

Leave a Reply

1 comment

  1. You can do that with a simple loop assuming that the users are also the authors of the post,
    create a template page, and copy the inside of your page.php to it.

    then replace the loop part with this code:

    <?php
    $args = array(
        'post_type' => 'company-listing', //change this to your actual CPT name
        'posts_per_page' => -1, //-1 to get all or any number you want to use with pagination
    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    User, email, post title, post status
        <div class="post company-listing">
        <ul>
    <?php  $user_info = get_userdata($post->post_author); ?>
            <li class="user">
                <?php echo $user_info->user_nicename; ?>
            </li>
            <li class="email">
                <?php echo $user_info->user_email; ?>
            </li>
            <li class="title">
                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            </li>
            <li class="status">
                <?php echo $post->post_status; ?>
            </li>
        </ul>
    </div>
    <div style="clear:both"></div>
    
    <?php endwhile; ?>
    
        <?php else: ?>
    
            <p class="no-data">
                <?php _e('Sorry, no page matched your criteria.'); ?>
            </p><!-- .no-data -->
     <?php endif; ?>
    

    and add this little code css to style it right:

    <style type="text/css">
    company-listing ul li{ float: left;padding: 2px;}
    </style>
    

    now you didn’t specify what is “USER” so i just showed you how to use user_nicename but after this line $user_info = get_userdata($post->post_author); you can use $user_info with:

    • user_firstname
    • user_lastname
    • ID
    • user_login
    • user_pass
    • user_nicename
    • user_email
    • user_url
    • user_registered
    • display_name

    and a few more.

    As for status i assume you are talking about the post_status so you will need to add 'post_status' => array('publish','pending','draft','future','private',....) to your $args.

    and if you are talking about a custom filed then just call that field with get_post_meta($post->ID,'status_field_name',true);

    Hope this helps