Support » Plugin: All in One SEO - Best WordPress SEO Plugin - Easily Improve Your SEO Rankings » Pagination not working with wp_reset_postdata

  • Resolved Xaibi Aslam

    (@lahorimela)


    Hello,
    I am using the latest WordPress and All in One Seo, my pagination is working fine. After some updates of All in One SEO, my titles are gone, after I change the code with wp_reset_postdata and now my pagination is gone. I do lots of searches but can’t figure it out. Here is the code.

    <?php $count = 1; ?>
    
    <?php 
    $temp = $sec_query;
    $sec_query= null;
    $sec_query = new WP_Query();
    $args =  get_post_meta($post->ID, 'job_tag', true);
    $sec_query->query('tag='.$args.'&posts_per_page=12&paged='.$paged);
    ?>
    
     
    <?php if ( $sec_query->have_posts() ) : ?>
     
    
    <?php while ( $sec_query->have_posts() ) : $sec_query->the_post(); ?>
     
    <?php get_template_part('includes/job-loop'); ?>
    
    		<!--Injecting Code-->
    			<?php if ($count == 6) : ?>
    				<div style="padding: 10px;">
    				<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    					<!-- JA Footer Responsive -->
    					<ins class="adsbygoogle"
         					style="display:block"
         					data-ad-client="PUB-ID"
         					data-ad-slot="4525903855"
         					data-ad-format="auto"></ins>
    				<script>
    				(adsbygoogle = window.adsbygoogle || []).push({});
    				</script>
    				</div>
    			<?php endif; $count++; ?>
    		<!--Injecting Code-->
    
    <?php endwhile; ?>
     
    <?php wp_reset_postdata(); ?>
     
    <?php else: ?>
     
    <?php _e( 'Sorry, no posts matched your criteria.' ); ?>
     
    <?php endif; ?>

    And this is my Pagination after this code..
    <?php if (function_exists('ja_pagination')) ja_pagination(); ?>

    Can you please help me to fix this issue?

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support arnaudbroes

    (@arnaudbroes)

    I don’t see anything wrong with that code at first glance. I’ve noticed you’ve posted about this elsewhere as well and are already following up with you. Let me know in case you’re not able to figure things out with them.

    – Arnaud

    Thread Starter Xaibi Aslam

    (@lahorimela)

    Yes, I have posted this thing to the forum as well, but nothing happened. My problem is still there. Here is my pagination code.

    <?php
    /* WordPress Pagination
     * author: Dimox
     * version: 2.1
    */
    function ja_pagination() {
    	global $wp_query, $wp_rewrite;
    	$pages = '';
    	$max = $wp_query->max_num_pages;
    	if (!$current = get_query_var('paged')) $current = 1;
    	$a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
    	$a['total'] = $max;
    	$a['current'] = $current;
    
    	$total = 1; //1 - display the text "Page N of N", 0 - not display
    	$a['mid_size'] = 2; //how many links to show on the left and right of the current
    	$a['end_size'] = 1; //how many links to show in the beginning and end
    	$a['prev_text'] = '<i class="ti-arrow-left"></i> Previous'; //text of the "Previous page" link
    	$a['next_text'] = 'Next <i class="ti-arrow-right"></i>'; //text of the "Next page" link
    
    	if ($max > 1) echo '<div class="pagination">';
    	//if ($total == 1 && $max > 1) $pages = '<ul class="pagination">Page ' . $current . ' of ' . $max . '</ul>'."\r\n";
    	echo $pages . paginate_links($a);
    	if ($max > 1) echo '</div>';
    }
    Plugin Support arnaudbroes

    (@arnaudbroes)

    @lahorimela have you checked what data is set to $wp_query? You might want to see which data the object is holding as that might give you a lead.

    – Arnaud

    Thread Starter Xaibi Aslam

    (@lahorimela)

    actually brother I am not a coder, I just find codes and do experiments. So I did the same here and it was working fine, when AIOSEO is updated to the latest version, I lost my titles from google. Then I use <?php wp_reset_postdata(); ?> to make my titles good but I lost pagination.

    Plugin Support arnaudbroes

    (@arnaudbroes)

    @lahorimela I think you might need to move the code that calls ja_pagination() to some other place before you call wp_reset_postdata(). That might do the trick.

    Thread Starter Xaibi Aslam

    (@lahorimela)

    I try to add this code before and after wp_reset_postdata

    <?php if (function_exists('ja_pagination')) ja_pagination(); ?>

    But it’s not working…I also try to add the default PREVIOUS & NEXT code, still not working.

    <div class="nav-previous alignleft"><?php previous_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php next_posts_link( 'Newer posts' ); ?></div>

    I think my main code is not good..

    • This reply was modified 2 months, 3 weeks ago by Xaibi Aslam.
    • This reply was modified 2 months, 3 weeks ago by Xaibi Aslam.
    • This reply was modified 2 months, 3 weeks ago by Xaibi Aslam.
    • This reply was modified 2 months, 3 weeks ago by Xaibi Aslam.
    • This reply was modified 2 months, 3 weeks ago by Xaibi Aslam.
    Thread Starter Xaibi Aslam

    (@lahorimela)

    Any help….

    Thread Starter Xaibi Aslam

    (@lahorimela)

    Please help me with this…..

    Plugin Support arnaudbroes

    (@arnaudbroes)

    @lahorimela I’m afraid that I don’t see what’s wrong with the code at first glance. You might need to engage someone to troubleshoot this for you on your website.

    Thread Starter Xaibi Aslam

    (@lahorimela)

    @arnaudbroes this code is working fine but my title are missing https://ibb.co/QPLw8fm, you can visit this page

    https://jobsalert.pk/dubai

    And this is the code:

    <?php $count = 1; ?>
    <?php 
    	$temp = $wp_query;
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$args =  get_post_meta($post->ID, 'job_tag', true);
    	$wp_query->query('tag='.$args.'&posts_per_page=20&paged='.$paged);
    	while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
     
    <?php get_template_part('includes/job-loop'); ?>
    
    		<!--Injecting Code-->
    			<?php if ($count == 6) : ?>
    				<div style="padding: 10px;">
    				<!--ADD HERE-->
    				</div>
    			<?php endif; $count++; ?>
    		<!--Injecting Code-->
    
        <?php endwhile; ?>
    • This reply was modified 1 month, 1 week ago by Xaibi Aslam.
Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.