I'm ussing in my site that code:
category-anuncios.php
<div class="listado-anuncios">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query=array("category_name"=>"anuncios","order"=>"ASC","posts_per_page"=>"1","page"=>$paged);
$objAnuncio = new WP_Query($query);
if ($objAnuncio->have_posts()){
?>
<ul>
<?php
while($objAnuncio->have_posts()){
$objAnuncio->the_post();
?>
<li>
<?php
the_title();
?>
</li>
<?php
}
?>
</ul>
<?php
if (function_exists("wp_pagenavi")){wp_pagenavi(array("query"=>$objAnuncio));}
wp_reset_postdata();
}
?>
</div>
I can see the content of my post well and show too the navigation...but, if I try to navigate to the second, third or other I have the error 404.
How can use that navigation with my custom query?
Edit:
Another way to test to fix the error:
Change the WP_Query for query_posts like that
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$categoria = $wp_query->query_vars["cat"];
query_posts('cat='.$categoria.'&posts_per_page=1&paged='.$paged);
But I've the same result: error 404
pre_get_posts
to alter the main query. This should solve your issue – Pieter Goosen Jan 13 '16 at 10:19query_posts
is not the normal loop. You should never ever usequery_posts
, it is a really bad wayy to create custom queries. Use the default loop, and usepre_get_posts
to alter the main query if you need to alter the main query – Pieter Goosen Jan 13 '16 at 11:06