当前作者的当前帖子

时间:2011-10-29 作者:boranb

如何检查当前帖子是否属于当前作者?这是我的基本代码`

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

还有,我如何向这些操作添加相同的控件`

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")
    {
        check_admin_referer(\'wpuf_del\');
        wp_delete_post($_REQUEST[\'pid\']);
        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;
    //d($posts);
`

谢谢

1 个回复
最合适的回答,由SO网友:EarnestoDev 整理而成

一个压缩版本,它不加载全局变量,但直接调用全局变量。

if(
    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!
}
您好。

结束

相关推荐

How to count get_users query?

我一直在到处寻找一种方法来计算get\\u用户查询的结果量。我发现的大部分内容都是统计帖子查询中的帖子总数,而不是统计get\\u users查询中的用户总数。有人能给我指出吗?非常感谢。