WordPress.org

Support

Support » Plugins and Hacks » Hacks » How Do I Get Post IDs by Author

How Do I Get Post IDs by Author

  • Jeffrey Pineda

    @jeffreycpineda

    Is there a way to get the Post IDs by using the Author ID.

    I’m want to update a post by a single author using “wp_update_post”.

    A snippet will be highly appreciated. Thank you.

Viewing 1 replies (of 1 total)
  • Hi,

    You can use this code:

    foreach(get_posts(array('author' => $author_id)) as $post)
    {
      //do what you want todo with post using $post->ID
    }

    Or low level db access method:

    global $wpdb;
    $pids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = 'publish' AND post_type='post'", $author_id));
    foreach($pids as $post_id)
    {
      //do what you want to do with post using $post_id
    }
Viewing 1 replies (of 1 total)
  • The topic ‘How Do I Get Post IDs by Author’ is closed to new replies.
Skip to toolbar