嗨,我正在尝试按作者在作者上显示文章。php,但我无法获取作者ID。域。com/author/user\\u 23/(显示该用户的帖子)
JQuery
jQuery(\'#menu_posts\').click(function(){
$.ajax({
type : \'GET\',
url : \'/wp-admin/admin-ajax.php\',
dataType : \'html\',
data : { action: \'user_posts\' },
success : function(data){
$(\'#user-tab\').html(data);
},
error: function(data){
alert("Error!");
return false;
}
});
});
功能
add_action(\'wp_ajax_user_posts\', \'user_posts\');
add_action(\'wp_ajax_nopriv_user_posts\', \'user_posts\');
function user_posts() {
$args = array(
\'author\' => $curauth->ID,
\'orderby\' => \'asc\',
\'post_type\' => \'post\',
\'posts_per_page\' => 10
);
$get_posts_query = new WP_Query( $args );
while ( $get_posts_query->have_posts() ) : $get_posts_query->the_post() ?>
(( html here ))
<?php
endwhile;
die();
}
作者。php
<?php $curauth = (get_query_var(\'author_name\')) ? get_user_by(\'slug\', get_query_var(\'author_name\')) : get_userdata(get_query_var(\'author\')); ?>