最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Display custom post type for specific user

programmeradmin0浏览0评论

I hope you can help me ... I already searched the information but I did not find anything useful.

I am doing a project where I created a post type (student_valuation) where the administrator places information about a member (student), there is a dropdown (student_name) to choose the student name.

I want to put this evaluation in a specific page for the student that will be logged. If someone has a query I can use ... thank you.

I hope you can help me ... I already searched the information but I did not find anything useful.

I am doing a project where I created a post type (student_valuation) where the administrator places information about a member (student), there is a dropdown (student_name) to choose the student name.

I want to put this evaluation in a specific page for the student that will be logged. If someone has a query I can use ... thank you.

Share Improve this question asked Aug 11, 2017 at 21:19 Rachel LaraRachel Lara 11 bronze badge 2
  • Hi. I'm not sure what exactly you are looking for... What do you want to hide? The student list? The page? The whole post type? – Johansson Commented Aug 11, 2017 at 21:46
  • Not understand the description but depends on the question title, you can wrap your wp_query in condition get_current_user_id(). – maheshwaghmare Commented Aug 12, 2017 at 9:15
Add a comment  | 

1 Answer 1

Reset to default 1

try this:

$args = array(
    'author' => get_current_user_id(),
    'post_type' => 'YOUR_CUSTOMPOST_TYPE',
);
$author_posts = new WP_Query( $args );
if ($author_posts->have_posts()): while ($author_posts->have_posts()) : $author_posts->the_post();

     //DISPLAY CONTENTS HERE

endwhile; endif;
wp_reset_postdata();
wp_reset_query();

replace YOUR_CUSTOMPOST_TYPE with your post type, what it does is finds posts of certain post type whose author is currently logged in user.

Currently it queries posts whose author is currently logged in user, you can list other users by using get_users(), full description here, and set 'author' => get_current_user_id() to 'author' => $ID_OF_USER

发布评论

评论列表(0)

  1. 暂无评论