3

I am a trying to create a dashboard like custom page template that list post of of the current logged in user. I've tried to find a solution on the net. but none were appropriate

8

this should work for you:

if ( is_user_logged_in() ):

    global $current_user;
    wp_get_current_user();
    $author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
    $author_posts = new WP_Query($author_query);
    while($author_posts->have_posts()) : $author_posts->the_post();
    ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>       
    <?php           
    endwhile;

else :

    echo "not logged in";

endif;
1

To include custom post time in the $author_query array, add another key=>value element to $author_query array.

Example:

$author_query = array(
   'posts_per_page' => '-1',
   'author' => $current_user->ID,
   'post_type'=>'your custom post type name'
);
  • Welcome to WPSE. Just a few notes to get you started: 1.) Always properly explain what your code does and how it works 2.) Please work on your code format when adding code. If you add code, highlight it in the code editor and click on the {} sign above the editor. Thank you – Pieter Goosen Oct 16 '14 at 18:11

protected by Community Nov 27 '16 at 12:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.