I need get posts by tag. I'm using such code for this:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'type' => get_post_type(),
'order' => 'ASC',
'posts_per_page' => 8,
'paged' => $paged,
'tag'=> $cur_tag
);
$query = new WP_Query($args);
var_dump($args);
?>
<div class="blogs-grid">
<?php
$postIndex=0;
?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php
//some code.....
$postIndex++;
?>
<?php endwhile; ?>
</div>
<div class="pagination blog-pagination">
<?php
echo paginate_links( array(/*some param*/) );
?>
</div>
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>
var_dump return such data for tag=blog
array(5) { ["type"]=> string(8) "blogpost" ["order"]=> string(3) "ASC" ["posts_per_page"]=> int(8) ["paged"]=> int(1) ["tag"]=> string(4) "blog" }
And does not display any records for this tag. In DB present 4 records.
Of course, I could use this code for view posts:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
But on this page I need to display the alaternative number of posts per page and etc.
I can not understand why WP_Query() does not work in my code. Can you help me with it?
What properties should be in array? My current $args is not working:
$args = array(
'type' => get_post_type(),
'order' => 'ASC',
'posts_per_page' => 8,
'paged' => $paged,
'tag'=> $cur_tag
);