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

admin2025-06-02  4

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.

How can I see only my posts on this 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.

How can I see only my posts on this page?

Share Improve this question edited Apr 9, 2014 at 5:57 stealthyninja 1,1301 gold badge15 silver badges21 bronze badges asked Sep 9, 2012 at 11:48 ashishjainashishjain 112 bronze badges 1
  • 2 possible duplicate of Code needed to only show users own posts in a multi-user account – kaiser Commented Sep 12, 2012 at 23:33
Add a comment  | 

2 Answers 2

Reset to default 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.

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 -->

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748800947a313830.html

最新回复(0)