WordPress: Custom Query - php

I have a custom query that uses an array merge so I can list articles and custom post type posts in one list, showing 5 at a time. Pagination below allows the user to see the rest of the results. I keep getting pagination errors, but I've tried virtually every variation of the $paged variable in my query to get pagination to work and it doesn't. I know it's me, and probably a simple syntax thing...but I'm stumped. Any ideas? (Note: this page has multiple, other custom queries above the one in question)
Here's my code:
<?php
$loop1 = array_merge( $wp_query->query,
array( 'post_type' => array('post','podcasts', 'cat' => $cat_ID ),
'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
'posts_per_page' => 5 ) );
query_posts( $loop1 );
while (have_posts()) : the_post(); ?>

have you tried?
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),

Related

Pagination not Working on Wordpress. Posts doesn't change

I'm trying to configure the Wordpress pagination in de Index homepage.
I've used the WP_Query with the regard of get_query_var('paged') before, just as the code shows:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'cat' => 7,
'posts_per_page' => 2,
'paged' => $paged
) );
?>
Then I used the native Wordpress function previous_posts_link() to go back onte the list of posts.
The problem that happens is that when the page loads, the url of the page changes, but the posts that shows are the same as before. Even to page 3 or 4, it just shows the same list of pages.
Where am I going wrong?

Wordpress pagination not working/displaying

Currently I am trying to get wordpress pagination to display at the bottom of the page but nothing shows up, if I echo out "paged" it outputs 1 so I believe it is correctly reading the page it is on. The loop I am using is as follows:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'company_list', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 6, 'paged' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
To echo out the actual pagination at the bottom of the page I am using:
echo paginate_links( $loop );
Currently no pagination is being displayed at the bottom of the page but the loop is working correctly. The page is also not set as a static front page.
Thanks.
1)You do not have to use question mark in your first row
$paged = (get_query_var('paged')) ?
2)also see :
https://stackoverflow.com/a/33757648/10210277

Pagination Not working - wordpress

Pagination on my website not working, everything else is fine, But when i click to go to "/page/2/3/" it shows no page found error.
Website : http://savemoney.16mb.com
Error pages: http://savemoney.16mb.com/page/2/
and currently Front Page set to "Latest Posts" (Not Static Page)
Pagination Code (Frontpage.php):
<?php
// show all coupons and setup pagination
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => $post_status, 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
?>
<?php get_template_part('loop', 'coupon'); ?>`
Any advice on how to get this pagination working correctly would be appreciated!
Thanks,
T
have you tried , "add_args" => false ?
here is more info for that https://core.trac.wordpress.org/ticket/30831

posts_per_page is displaying 2 less items than intended

my first question here, so I'm sorry if I do something wrong :S
I have a custom post type, called "portfolio", and a template which I'm using to display these posts. Unfortunately, when using posts_per_page, the template is constantly displaying 2 less items than I input. Here is what I have thus far:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array('post_type' => 'portfolio', 'paged' => $paged,
'posts_per_page' => '4');
query_posts($args);
if( have_posts() ) :
?>
It then continues into the while loop for posting the results. Any ideas on what could be causing this?
Try to reset your query before your code.
wp_reset_query();
query_posts($args);
Function refrence: wp_reset_query()

Joining two query_posts codes

How do I join these two codes so that they work?
<?php query_posts( array(
'posts_per_page' => 16,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), ));
?>
and
<?php query_posts('category_name=' . $category->cat_name . '&paged='. get_query_var('paged')); ?>
The first one has working navigation (when I click older/newer posts) and the second one doesn't (it returns the same page with the correct URL). I had that problem with my other template so I used the code posted above to get the navigation to work.
Also, the first code shows 16 posts and the second one only 5.
I tried combining them by just adding those two lines to the second code but it either gives me an error, gives me a non-working navigation or it simply gives the 16 posts but not displayed by the category.
try:
<?php
query_posts(
array(
'posts_per_page' => 16,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
'category_name' => $category->cat_name
)
);
?>

Categories