WordPress.org

Ready to get started?Download WordPress

Forums

Query posts written by specific user (3 posts)

  1. hraban
    Member
    Posted 2 years ago #

    Hey,
    Is there any way to query posts written by some specific user (currently logged in)?
    I know this can be achieved by custom SQL query, but there should be a native built in function, isn't it?

  2. h0tw1r3
    Member
    Posted 2 years ago #

    $current_user = wp_get_current_user();
    if ( $current_user->ID > 0 ) {
        $query = new WP_Query('author='.$current_user->ID);
        while ( $query->have_posts() ): $query->the_post();
            the_title();
        endwhile;
        wp_reset_postdata();
    }
  3. hraban
    Member
    Posted 2 years ago #

    Thanks, that did the trick! Shame I did not notice the presence of author argument in codex.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.