I have a custom theme in WordPress and I just created a custom pagination for a custom query.
Once I click page 2 or higher, it will redirect me to [URL]/[URI]/page/2
, yet in my screen it will only show the code in index.php
.
Somehow this URI with this new parameter ( page
) is loading the wrong file in my WordPress theme. How can I solve this?
This is my query:
//Parametro para saber cuantos posts abran por pagina!
$post_per_page = 6;
//Extracción de la pagina actual
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
// set up or arguments for our custom query
$query_args = array(
'post_type' => 'recetas_practicerdo',
'category_name' => 'dia_a_dia',
'order' => 'ASC',
'posts_per_page' => $post_per_page,
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
Pagination is working good and it echoes the right content. Every button in my <ul><li>
elements are correct.
Yet the result is the wrong file. =(
After sesarching for a while I decided to use the get_template_part( ) function in wordpress.
I grab my URI and created some logical rules. If they were true, load the template from where my pagination should be redirecting.
I know it's not the best solution but didn't find any answer on the web.
Some answers said that pagination with custom wp_queries should break some plugins (which is my case).
Also, after I load the right template, I had to also create a head-title for every redirect I did.
If someone knows how to really fix this problem, I will be grateful with the help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.