How to show user’s own post in a specific page

I created one page for posts and changed the default post page to that page in Settings > Reading. When registering for the site the default new user role is subscriber.

The problem is after the login when I click on my diaryview page it shows all the posts of other users but I want to see only my posts in my diaryview post page.

Read More

How can I see only my posts on this page?

Related posts

Leave a Reply

2 comments

  1. Try using wp_query

    Here is the codex link:

    WP_Query – Docs – WordPress

    Here is an example of something that may help:

    global $current_user;
          get_currentuserinfo();
    $authorID = $current_user->ID;
        $args = array(
                  'post_type' => 'post',//or whatever you need
                  'posts_per_page' => 5,
                  'author' => $authorID
                  );
    
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query($args);
    

    You could use this in you own template page to display only the current user’s posts.

  2. This worked for me. Comment out the post_priority

    <div class="leftdash">
    <h2>My Post</h2>
    <?php
     $current_user = wp_get_current_user();
    $args = array(
    'author'        =>  $current_user->ID,
    'orderby'       =>  'post_date',
    'order'         =>  'ASC',
    'post_status' => 'publish',
    'posts_per_page' => -1
    );
    
    $current_user_posts = get_posts( $args );
    //echo "<pre>"; print_r($current_user_posts); die; 
    foreach ($current_user_posts as $post) {
    ?>
    
        <article id="post-<?php echo $post->ID; ?>" class="post-814 post type-post status-publish format-standard hentry category-uncategorized tag-priority-6">
    <header class="page-header">
            <h1 class="page-title"><a href="<?php echo $post->guid; ?>" rel="bookmark"><?php echo $post->post_title; ?></a></h1>
                    <div class="entry-meta">
                    </div><!-- .entry-meta -->
            </header><!-- .entry-header -->
        <div class="entry-content">
            <p><?php $content = $post->post_content; 
                $trimmed_content = wp_trim_words( $content, 5, NULL );
                echo $trimmed_content
            ?></p>            
         </div><!-- .entry-content -->
    <footer class="entry-meta">
        <span>Priority <?php  echo get_field( "post_priority", $post->ID ); ?></span>
         <span class="cat-links">
                Posted in <?php $category_detail=get_the_category($post->ID);//$post->ID
                    foreach($category_detail as $cd){
                     ?>
                            <a  href="<?php echo get_category_link($cd->cat_ID); ?> ">
                            <?php echo $cd->cat_name; ?> </a>
    
                     <?php
                    } ?>
                 </span>
    
                        <span class="tags-links">
                Tagged <?php $postid = $post->ID;
                    $posttags =  get_the_tags($postid); 
                    if ($posttags) {
                    foreach($posttags as $tag) {
                    ?>
                         <a href="<?php echo get_tag_link($tag->term_id); ?>" rel="tag"><?php echo $tag->name ; ?></a>            
    
                    <?php } } ?>
                    </span>
    
                <span class="comments-link"><a href="<?php echo get_comments_link( $post->ID ); ?>">Leave a comment</a></span>
                <span class="edit-link"><a class="post-edit-link" href="<?php echo get_edit_post_link($post->ID); ?>">Edit</a></span>
    
        </footer><!-- .entry-meta -->