0

I need to find a list of custom posts where the logged in user is the author of the post

  • Please try this solution wordpress.stackexchange.com/a/56410/137328 – Gufran Hasan Nov 1 at 5:34
  • @GufranHasan That question doesn't have anything to do with Pratikb's. They're asking about getting posts by author, not role. – Jacob Peattie Nov 1 at 5:53
  • 1
    @pratikb-simform Did you try anything? If you could paste some sort of code you might have tried. – Kumar Nov 1 at 7:51
  • I have used this code so far but no success $author_query_id= array('post_author' => $userID, 'post_type'=>'estate_agent'); $author_posts_id = new WP_Query($author_query_id); It shows all posts not with the author id given – Pratikb.Simform Nov 1 at 7:55
  • Are you defining $userID anywhere? – Jacob Peattie Nov 1 at 8:22
1

I have found a solution for it and here is it

$current_user = wp_get_current_user();
$userID       = $current_user->ID;

  $args =array( 'author' => $userID,'post_type' => 'custom_post' ) ;
  $authors_posts = get_posts($args);


    foreach ( $authors_posts as $authors_post ) {
        $content= $authors_post->post_title;
    }

echo $content;

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.