Pagination link is not working /page/2 - NOT FOUND - Wordpress - php

I need to create a paginator in my blog page, until this its good, but when i click in a link of my pagination i got NOT FOUND page, i need to know if i need to able something in the panel to wordpress able the access to ?page=N
function:
function get_pagination($the_query) {
global $paged;
$total_pages = $the_query->max_num_pages;
$big = 999999999;
if ($total_pages > 1) {
ob_start();
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '/page/%#%',
'current' => $paged,
'total' => $total_pages,
'prev_text' => '',
'next_text' => ''
));
return ob_get_clean();
}
return null;
}
my blog code
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// echo $paged;
$produtos = new WP_Query(array(
'post_type' => 'blog',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'asc',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'categorias',
'field' => 'slug',
'terms' => ACTIVE
)
)
));
while ( $produtos->have_posts() ) : $produtos->the_post();
//CONTENT
endwhile;
echo get_pagination($produtos);

Go to admin Dashboard then Settings->Reading then set Blog pages show at most is equal to you query posts_per_page. So in your query if you set posts_per_page => 2 then Blog pages show at mostwill be 2

This is what I found and resolved the issue I had!
[...] I needed to go into the wp-admin page (the wordpress dashboard)
and go to Settings then Reading and in the "Blog pages show at most"
field I changed the value from '10' to '6' (the number of posts I
indicated in
$wp_query->query('showposts=6&cat=1'.'&paged='.$paged);)

use following paged query
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$produtos = new WP_Query(array(
'post_type' => 'blog',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'asc',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'categorias',
'field' => 'slug',
'terms' => ACTIVE
)
)
));
while ( $produtos->have_posts() ) : $produtos->the_post();
//CONTENT
endwhile;
echo get_pagination($produtos);

Please check your .htaccess file. It should contain a rewrite rule to enable pagination with slashes.
Please see:
"Using pretty permalinks" - http://codex.wordpress.org/Using_Permalinks

Problem: When we click on next page then wordpress redirects on first
------- page or on same pag.
Solution: put this code snippet in your themes functions.php file.
--------
add_filter('redirect_canonical', 'pif_disable_redirect_canonical');
function pif_disable_redirect_canonical($redirect_url)
{
if (is_singular()) $redirect_url = false;
return $redirect_url;
}
---------------------------------------------------
! it has worked for me , I hope it works for you

Go to your wordpress Dashboard Settings then Reading and in the "Blog pages show at most" field, changed the value from '10' to '1'
cheers!

Related

Wordpress custom post-type pagination with wp-pagenavi

I have a custom post type called criticos and I'm having problems with pagination.
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 8,
'post_type' => 'avaliacoes',
'paged' => $paged,
//'orderby' => 'meta_value_num',
//'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'critico', // name of custom field
'value' => '"' . $Dados['id'] . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
));
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
foreach ($loop->posts as $avaliacao) {
//Do Stuff Here
}
}
wp_pagenavi( array( 'query' => $loop ) );
wp_reset_postdata();
The pagination is not working when go to the page 2 redirect to first page.
My page is single-criticos
PS: English isn't my first language.

After redirct url pagination not working

This is my pagination code. It's worked well after redirect page url. When I am redirecting url to another page this code not worked. This custom post pagination.
before redirect the pagination hover url was:
http://xxxx/?industry=26&posts_per_page=12&page=3
and after redirect the pagination hover url was (and its not working):
http://xxxx/newpage/?page=2&industry=26&location_company=0&employees=0&type=video
<?php
echo paginate_links( [
'prev_text' => __( 'Previous', 'bizcast' ),
'next_text' => __( 'Next', 'bizcast' ),
'before_page_number' => '',
'screen_reader_text' => '',
'total' => $videos->max_num_pages,
'format' => '?page=%#%',
'current' => ($_GET['page'] ? $_GET['page'] : 1),
'type' => 'list'
] );
?>
Add
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
before loop start and add 'paged' => $paged in wp query arguments.
For example:
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'category_name' => 'tutorials',
'posts_per_page' => 5,
'paged' => $paged
);

Wordpress WP-PageNavi not working with custom query

I have been trying to solve this for a while now but with no success. I have read other similar posts but they are not working for me.
I have created a custom query with displays the correct results and the pagination shows but when i click on the page 2 etc, the url changes accordingly but the same posts remain.
My custom query is:
$sale_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'paged' => get_query_var('page'),
'meta_query' => array(
array('key' => $nvr_initial.'_status',
'value' => array('For Sale'),),),));
and my other code is:
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $sale_properties->max_num_pages > 1 ) : ?>
<?php if(function_exists('wp_pagenavi')) { ?>
<?php wp_pagenavi( array( 'query' => $sale_properties ) ); ?>
<?php }else{ ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Previous', THE_LANG ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Next <span class="meta-nav">→</span>', THE_LANG ) ); ?></div>
</div><!-- #nav-below -->
<?php }?>
<?php endif; wp_reset_query();?>
I've tried page, paged and:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
Could someone please help me out as it's driving me crazy
Kind regards
S
Replace page with paged in below code:
$sale_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'paged' => get_query_var('page'),
'meta_query' => array(
array('key' => $nvr_initial.'_status',
'value' => array('For Sale'),),),));
to
$sale_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'paged' => get_query_var('paged'),
'meta_query' => array(
array('key' => $nvr_initial.'_status',
'value' => array('For Sale'),),),));
or put
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
above the query and pass $paged variable in query at the place of
get_query_var('page'),
Hopes it will help.
EDIT:
Wordpress standard way:
place on top:
$big = 999999999;
$current_page = get_query_var( 'paged', 1 );
$args = array(
//your query arguments
'paged' => $current_page
);
$my_query = new WP_Query($args);
Use loop like below:
while ( $my_query->have_posts() ) : $my_query->the_post();
// your code
endwhile;
then
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $my_query->max_num_pages
) );
place above where you want to print paging.
I had my custom wp query in the functions.php file. After moving it to my custom page template it worked
$sale_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'paged' => get_query_var('paged'),
'meta_query' => array(
array('key' => $nvr_initial.'_status',
'value' => array('For Sale'),),),));

Page navi is not working in custom taxonomy template?

I have a custom taxonomy template taxonomy-event-category.php and i
have added following code for pagination but it does not work.
<?php
$current_term = single_term_title("", false);
$cat_id = get_cat_ID('My Category');
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args=array(
'post_type' => 'event',
'post_status' => 'publish',
'posts_per_page' => 1,
'paged'=>$paged,
'caller_get_posts'=> 1,
'tax_query' => array(
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => $current_term,
),
),
);
$new = new WP_Query($args);
while( $new->have_posts() ): $new->the_post();
/* OUTPUT HERE */
endwhile;
if ( function_exists( 'wp_pagenavi' ) ) {
wp_pagenavi( array( 'query' => $new ) );
}
wp_reset_postdata();
?>
whenever i click on the next page or second page getting me 404
page not found error.
Anyone have idea about how pagnavi work in custom taxonomy template.

Trying to reorder posts by event date

I'm using "the events calendar" plugin in WP which has a feature to allow event posts to show up as regular posts. I currently have a slider on my homepage that I would like to show featured events on. I was able to get it to show events as a "featured" category, but am having trouble ordering it by event date instead of publish date. This is what I have now.
Here is the original code just calling the specific category posts
<?php query_posts ('category_name=' .$slide.'&posts_per_page='.$bvkPP.'&paged='.$paged ); ?>
This is what I changed it to
<?php query_posts( array ('category_name=' .$slide.'&posts_per_page='.$bvkPP.'&paged='.$paged, 'orderby' => 'meta_value','meta_key' =>'_EventStartDate','order' => 'ASC',) ); ?>
This affectively ordered it by event date, but has overridden the category and is just calling for all events. Any thoughts on how to get just the specific category to show up?
Thanks!
I finally got it figured out. Here's what I came up with.
<?php query_posts( array(
'category_name' => $slide,
'posts_per_page' => $bvkPP,
'paged'=> $paged,
'orderby' => 'meta_value',
'meta_key' => '_EventStartDate',
'order' => 'ASC',
'eventDisplay'=> 'startDate',
'post_type'=> 'tribe_events' ) ); ?>
Thanks for the help!
get all event using your cat id.
<?php
$paged = ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'id',
'terms' => '17' //17 is cat id
)
),
'eventDisplay'=>'startDate',
'post_type'=>'tribe_events',
'orderby'=>'meta_value',
'meta_key'=>'_EventStartDate',
'posts_per_page' =>10,
'paged' => $paged,
'order' => 'ASC',
);
query_posts($args);
while ( have_posts() ) : the_post(); ?>
//your code here for get title/content
<?php
endwhile;
wp_reset_query();
?>

Categories