Filtering posts in a template-based page
-
Hello everyone,
I have a template-based page where I want to show posts of a certain category and filtering them by a tag they have so I can exclude some posts.
The code is this, as you see I have ‘tag’=>’rassegna_stampa’ in $args:<?php
if (is_page_template()) :
$paged = ( get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args=array(
‘category__in’=>array(24),
‘posts_per_page’=>6,
‘caller_get_posts’=>1,
‘tag’=>’rassegna_stampa’,
‘paged’=>$paged
);query_posts($args);
print_r($wp_query);
endif;
?>
<?php if (have_posts()) : while (have_posts()) : the_post();
echo ‘<div class=”category_description”>’; if ( in_category(’24’) ) the_content(); echo ‘</div>’;
endwhile; ?><div class=”navigation”>
<span class=”previous-entries”><?php next_posts_link(Previous entries…’) ?></span><span class=”next-entries”><?php previous_posts_link(Next entries…’) ?></span>
</div><?php else : ?>
<span class=”center”>Sorry, no posts in this page.</span>
<?php endif; ?>
And the result of print_r($wp_query) is this:WP_Query Object ( [query_vars] => Array ( [category__in] => Array ( [0] => 24 ) [posts_per_page] => 6 [caller_get_posts] => 1 [tag] => rassegna_stampa [paged] => 1 [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [hour] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [cat] => [tag_id] => 59 [author_name] => [feed] => [tb] => [comments_popup] => [meta_key] => [meta_value] => [preview] => [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( [0] => rassegna_stampa ) [tag_slug__and] => Array ( ) [suppress_filters] => [post_type] => post [nopaging] => [comments_per_page] => 50 [order] => DESC [orderby] => bin09_posts.post_date DESC ) [request] => SELECT SQL_CALC_FOUND_ROWS bin09_posts.* FROM bin09_posts INNER JOIN bin09_term_relationships ON (bin09_posts.ID = bin09_term_relationships.object_id) INNER JOIN bin09_term_taxonomy ON (bin09_term_relationships.term_taxonomy_id = bin09_term_taxonomy.term_taxonomy_id) INNER JOIN bin09_terms ON (bin09_term_taxonomy.term_id = bin09_terms.term_id) WHERE 1=1 AND bin09_term_taxonomy.taxonomy = ‘category’ AND bin09_term_taxonomy.term_id IN (’24’) AND bin09_term_taxonomy.taxonomy = ‘post_tag’ AND bin09_terms.slug IN (‘rassegna_stampa’) AND bin09_posts.post_type = ‘post’ AND (bin09_posts.post_status = ‘publish’) GROUP BY bin09_posts.ID ORDER BY bin09_posts.post_date DESC LIMIT 0, 6 [post_count] => 0 [current_post] => -1 [in_the_loop] => [post] => [comments] => [comment_count] => 0 [current_comment] => -1 [comment] => [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => 1 [is_tag] => 1 [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_comments_popup] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_paged] => 1 [query] => Array ( [category__in] => Array ( [0] => 24 ) [posts_per_page] => 6 [caller_get_posts] => 1 [tag] => rassegna_stampa [paged] => 1 ) [posts] => Array ( ) ) Sorry, no posts in this page.
But it doesn’t show any post, even the message “Sorry, no posts in this page”. Indeed, if I remove ‘tag’=>’rassegna_stampa’ from $args and put has_tag(‘rassegna_stampa’) inside: if ( in_category(’24’) ) the_content(); it shows 6 posts only at first page, and 4 posts in the second and 2 posts in the third; plus at last page it still show the link previous entries when it shouldn’t.
I suspect it’s just extracting ALL posts but simply without showing those that doesn’t have the tag ‘rassegna_stampa’ but effectively for the Loop they are 6 per page.So I am asking you how I can filter those posts by tag in the $args correctly so I can see posts?…
Thanks to everyone in advance!!
Ciao
Luigi
- The topic ‘Filtering posts in a template-based page’ is closed to new replies.