WordPress.org

Support

Support » How-To and Troubleshooting » Query posts written by specific user

Query posts written by specific user

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • $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();
    }

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query posts written by specific user’ is closed to new replies.
Skip to toolbar