I'm ussing in my site that code:


    <div class="listado-anuncios">
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                 
                    $objAnuncio = new WP_Query($query);
                    if ($objAnuncio->have_posts()){
                        if (function_exists("wp_pagenavi")){wp_pagenavi(array("query"=>$objAnuncio));}

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?


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"];

But I've the same result: error 404

  • Do not use a custom query, use pre_get_posts to alter the main query. This should solve your issue Jan 13, 2016 at 10:19
  • I use other way:, I try to use the "normal" loop in wordpress (query_posts) but I've the same result: error 404...I wrote the code in the question too
    – Marcos
    Jan 13, 2016 at 11:04
  • query_posts is not the normal loop. You should never ever use query_posts, it is a really bad wayy to create custom queries. Use the default loop, and use pre_get_posts to alter the main query if you need to alter the main query Jan 13, 2016 at 11:06
  • Yes, you are right @PieterGoosen... I can fixed ussing pre_get_post in my functions file. I will write the answer...Thanks!
    – Marcos
    Jan 13, 2016 at 15:20

1 Answer 1


Just work including that code in the functions file:

function mod_query($query){
    $entradas = get_category_by_slug('anuncios');    
    if ((!is_admin() && $query->is_main_query())){

The file to show the content of the category is a normal file (without extra configuration)

Thanks to @Pieter Groosen for the orientation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.