Wordpress-Ajax调用当前作者数据

时间:2018-10-05 20:18:40

标签: ajax wordpress author

我具有用于创建Ajax调用以在服务器端获取当前作者数据的功能,但无法正常工作总是给我错误,而且我无法弄清楚问题出在哪里。

先谢谢了。

更新

问题出在$curauth = get_userdata(intval(intval($_POST['author']));这行中,两次重复执行intval。

add_action('wp_ajax_user_following_by_ajax', 'user_following_by_ajax_callback');
add_action('wp_ajax_nopriv_user_following_by_ajax', 'user_following_by_ajax_callback');

function user_following_by_ajax_callback() 
{
    check_ajax_referer('user_more_following', 'security');
    $paged = $_POST['page'];

    /// detect the author data with the name or with the author id
    $curauth = NULL;

    if( isset($_POST['author_name']) AND trim($_POST['author_name']) != '' )
    {
        $curauth = get_user_by('slug', trim($_POST['author_name']) );
    }
    elseif( isset($_POST['author']) AND intval($_POST['author']) > 0 )
    {
        $curauth = get_userdata(intval(intval($_POST['author']));   
    }

    if( !is_null($curauth) )
    {
        $include = get_user_meta($curauth->ID, '_pwuf_following', true);


        if ( !empty( $include ) ) 
        {

            echo 'Not followed anyone yet.';

        } 
        else 
        {
            //// continue with your existing code. /////
        }

    }
    else
    {
        echo 'Not followed anyone yet.';
    }
}

0 个答案:

没有答案