我在此代码中遇到author_id时遇到问题。什么都不显示。有些人可以帮助我吗?
整个代码:(我正在尝试获取post的同一作者的custom_post_type值。
<?php global $query_string;
query_posts( $query_string . '&orderby=rand' ); ?>
<?php while(have_posts()): the_post();
$author = get_the_author();
echo 'Autor:'.$author;
$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
else: // if it has no post
continue; // we don't display the post
endif;
wp_reset_postdata();
?>
答案 0 :(得分:0)
<?php
$blogusers = get_users('role=author');
foreach ($blogusers as $user) {
echo 'Author ID: '.$user->ID;
$author_id = $user->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
else: // if it has no post
continue; // we don't display the post
endif;
wp_reset_postdata();
} // end foreach
?>
这是否符合您的要求?