Can’t echo get_delete_post_link

Is the user logged in and is allowed to delete posts of this post type? There are three checks inside the get_delete_post_link function before anything starts happening:

if ( !$post = get_post( $id ) )
    return;

$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object )
    return;

if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) )
    return;

I’m wild-guessing it’s the third check that’s failing in your case. You can paste them into your code and replace return; with debugging code to see what’s going on:

if ( !$post = get_post( $id ) ) {
    echo 'could not get post. ';
} else {
    echo 'got post. ';
}

$post_type_object = get_post_type_object( $post->post_type );
if ( !$post_type_object ){
    echo 'could not get post object. ';
} else {
    echo 'got post object. ';
}

if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ){
    echo 'user does not have proper capability. ';
} else {
    echo 'user is ok to delete this post. ';
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)