global $post;
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'post\',
);
$the_query = new WP_Query( $args );
$array = get_object_vars($the_query); //convert the object into an array (manual workaround)
if ( $the_query->have_posts() ) :
$count = 0; //start an iteration count
while ( $the_query->have_posts() ) : ?>
<? $the_query->the_post(); ?>
<?php $postarray = get_object_vars($array[\'posts\'][$count]);
//convert the post object into an array
?>
<div class="row">
<div class="col-md-6">
<div class="card">
<h4><?php echo get_the_title(); ?></h4>
<p><?php echo get_the_excerpt(); ?></p>
<?php the_permalink() ?>
<!-- the guid is now accessable -->
<a href="<?php echo $postarray[\'guid\']; ?>">Read More</a>
</div>
</div>
</div>
<? endwhile;
else :
echo wpautop( \'Sorry, no posts were found\' );
endif;
我已经提到了关于这一点的其他问题,但是global $post;
在循环之外(参考Post Loop not Returning Permalink) 我还尝试了使用一系列函数来获取/显示permalink和guid值(参考get_the_permalink()
Documentation 同样值得注意的是get_the_ID()
返回当前查看的页面id,而不是迭代的帖子id
此外,这些都包含在一个shortcode函数中。
非常感谢您的帮助:)