0

I would like to create a page that shows only posts written by the user logged in and get a link (such as www.example.com/AuthorPostsID) to put on the menu. I'm trying for two days. Does anyone know how to fix it? Thanks

EDIT: I tried using the following code, putting it in the function.php file, but I do not know how to proceed:

if ( is_user_logged_in() ):    
    global $current_user;
    get_currentuserinfo();
    $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;
  • 2
    Since you have been trying for two days, certainly there is code you can post even if that code doesn't work. – s_ha_dum Feb 14 '14 at 15:30
  • 1
    You added a comment that had some code in it, and then deleted the comment. (It saw it just before you deleted). Edit that code into the question. – s_ha_dum Feb 14 '14 at 15:48
  • I'm sorry, I deleted the code because it was bad formatted as comment – Comphez Feb 14 '14 at 16:09
  • Yes, formatting in comments is very minimal. You should always edit important information into the question or answer. – s_ha_dum Feb 14 '14 at 16:14
0

You don't need to put your code in your theme functions. This needs to be a custom page template. Learn about page templates here:

http://codex.wordpress.org/Page_Templates

Your code is custom loop so you need to also learn about loops and then using WP_Query so next stop will be here:

http://codex.wordpress.org/The_Loop

Then read this page:

http://codex.wordpress.org/Class_Reference/WP_Query

After you do this you will be ready to implement your custom loop to show authors their posts.

Study, the codex so that you have a better understanding of how WordPress works before you make changes to things that will break WordPress.

Then when you ask questions here you will be able to get a better answer to problems that you are having because the people here will understand your question better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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