404 error PageNavi custom type taxonomy | wordpress

Your problem is definitly your custom query. There are a problem or two with your custom query which I will not handle now. You should work through this page (WP_Query) on how to properly construct a custom query

Your real issue here is, and the question you must ask youself, is the custom query necessary? And the straight answer should be a solid NO. Custom queries should always be avoided in favor of the main query on the home page and any type of archive page. The main query is very specific to the particular page being requested, something that is not replicated by your custom query.

Although these custom queries works, the real issues comes in when you try to paginate, as you have experienced now.

The basic layout with the default loop to display the main query’s results of any template should look like this

if( have_posts() ) {
    while( have_posts() ) {
        the_post();

        // CALL YOUR TEMPLATE TAGS

    }
} 

The if condition is not always necessary like on the single.php template and archive templates. As you can see, NO custom queries.

Any changes that you need to make to the main query ( except on page templates where you will need to run a custom query) can be done via pre_get_posts which is the correct way of changing what is being queried on a template. For additional info on the above said, check this post

So, your solution would be, delete all parts of your custom query, and replace it with the default loop as I have given above, just add your loop objects and HTML mark up to that, and then you can paginate as normal

EDIT

From the code from your pastes, your query looks fine now. That is how it should be.

Your root cause of all of this is your post type, Rock. You cannot use camelcase in custom post type names (this goes for custom taxonomy and function names). You should consider renaming your custom post type to rock.

And remember, flush and reflush your permalinks to make sure your changes has taken effect after you have updated your custom post type code

EDIT 2

You either did not read the linked posts or you just took a suicidal shortcut with query_posts. Please reread the linked post in this answer. You should NEVER ever make use of query_posts.

Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination).

Delete this line

 $posts=query_posts($query_string . '&orderby=asc&posts_per_page=5'); 

This line is the root of your evil on your page

You can change pagination on a per page basis with pre_get_posts which is the correct way of doing this. If you need to change the number of posts on just your curiosity term page, you can add the following to your functions.php (Note: this requires PHP 5.3+)

add_action( 'pre_get_posts', function ($q ) {
    if( !is_admin() && $q->is_main_query() && $q->is_tax( 'genero', 'curiosity' ) ) {
       $q->set( 'posts_per_page', 3 );
       $q->set( 'order', 'ASC' );
    }
)};

EDIT 3

For versions prior to PHP 5.3, the above won’t work as anonymous functions was introduced only in PHP 5.3. For these versions, try the following

add_action( 'pre_get_posts', 'wpse170243_custom_ppp' );
function wpse170243_custom_ppp($q ) {
    if( !is_admin() && $q->is_main_query() && $q->is_tax( 'genero', 'curiosity' ) ) {
       $q->set( 'posts_per_page', 3 );
       $q->set( 'order', 'ASC' );
    }
}

Leave a Comment