How Do I Get Post IDs by Author (2 posts)

  1. Jeffrey Pineda
    Posted 5 years ago #

    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.

  2. wpua
    Posted 5 years ago #


    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

Topic Closed

This topic has been closed to new replies.

About this Topic