我在获取此代码中的author\\u id时遇到问题。不要什么都不显示。有人能帮我吗?
<?php global $query_string;
query_posts( $query_string . \'&orderby=rand\' ); ?>
<?php while(have_posts()): the_post();
$author_id = the_author_meta(\'ID\');
echo \'Autor:\'.$author_id;
$ofertas = array();
// Second Loop
$i = 0;
$args = array(
\'author\' => $author_id,
\'post_type\' => \'ofertas\'
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post(); // check if it has offers, if it has, loop over the offers
$ofertas[$i][\'title\'] = get_the_title(); // or anything you need
$i++;
endwhile; // close the loop
else: // if it has no post
continue; // we don\'t display the post
endif;
wp_reset_postdata();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
最合适的回答,由SO网友:bueltge 整理而成
检查中的值get_query_var()
作用例如,这是可行的:--
$author = get_user_by( \'slug\', get_query_var( \'author_name\' ) );
echo $author->ID;
如果您只喜欢post的作者,请在循环中使用模板标记
get_the_author()
.