WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how can i check if the current post belongs to the current author? this is my basic code; `

if($curpost) {
            } else {
                $error = "there is no post.";


also how can i add the same control to these action; `

function wpuf_user_dashboard_post_list() {
    global $wpdb, $userdata;

    get_currentuserinfo(); // grabs the user info and puts into vars

    //delete post
    if ($_REQUEST['action'] == "del")
        echo '<div class="success">deleted.</div>';

    //get the posts
    $sql = "SELECT ID, post_title, post_name, post_status, post_date "
            . "FROM $wpdb->posts "
            . "WHERE post_author = $userdata->ID AND post_type = 'post' "
            . "AND (post_status = 'publish' OR post_status = 'pending' OR post_status = 'draft') ";

    $posts = $wpdb->get_results($sql);
    $count = 1;



share|improve this question
There are dozens of Qs about this topic. – kaiser Oct 29 '11 at 11:13
up vote 1 down vote accepted

A compacted version that does not load the globals yet calls upon them directly.

    is_user_logged_in() and // Force user validation... STUFF
    !empty($GLOBALS['post']) and // Check if a $post exists in globals
    !empty($GLOBALS['current_user']) and // Check if current_user exists in globals
    ($GLOBALS['current_user']->ID == $GLOBALS['post']->post_author) // Match User IDs
    // This is your Author speaking, use the Force!


share|improve this answer
thank you earnesto – boranb Oct 29 '11 at 15:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.