Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3360814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:02:54+00:00 2026-05-18T03:02:54+00:00

I’m trying to make a pagination system, and to make it work on every

  • 0

I’m trying to make a pagination system, and to make it work on every page I’m using the $query_string variable, which supposedly contains all the information about the category, etc.

So I’m doing something like this:

add_action('wp_ajax_and_action', 'get_posts_page');
add_action('wp_ajax_nopriv_and_action', 'get_posts_page');

function get_posts_page() {

$query_string = $_POST['query_string'];

global $wpdb;   


query_posts($query_string . '&posts_per_page=10&post_status=publish&offset='.$_POST['off']);    

It’s in my functions.php file. I’ve globalized the $query_string variable in my header.php file. The $_POST['query_string'] is coming from a javascript function (also in my functions.php file) which I’ve set to be in wp_head (so the head of the document I assume). It’s posting a bunch of data to the PHP function:

$.post('<?php bloginfo('siteurl') ?>/wp-admin/admin-ajax.php', {
action: 'and_action',
off: offset+number,
pagenumber: page_number,
query_string: '<?php echo $query_string; ?>'
}, function(data) {

However, upon further inspection it shows the query_string variable as null.
So when I do: <?php echo $query_string ?> nothing returns. Any ideas why that might be? Thanks 🙂


Updated

Heres an Update

functions.php

The Javascript:

   add_filter('wp_head', 'javascript_page');

function javascript_page() {
?>

    <script type="text/javascript">
    $(document).ready(function() {

        var number = 10;
        var offset = 0;
        var page_number = 2;
        var busy = false;

        /* Bind the scroll function to an event */
        $(window).bind('scroll', function(e) {


            /* If the scroll height plus the window height is more than the document height minus 10, continue */
            if($(window).scrollTop() + $(window).height() > $(document).height() - 10 && !busy) {


                busy = true;    

                /* Quick message so you know more stuff is loading */
                $('.loading-more').html('Click to load more posts..');

                $.post('<?php bloginfo('siteurl') ?>/wp-admin/admin-ajax.php', {
                    action: 'and_action',
                    off: offset+number,
                    pagenumber: page_number,
                    query_string: '<?php echo $query_string; ?>'
                    }, function(data) {


                        offset = offset+number; 

                        $('.empty-div').append('<div class="pages"><p>Welcome to <strong>Page '+page_number+'</strong></p></div><hr />'+data);


                        busy = false;
                        page_number += 1;


                });


            }

        });


        $('.loading-more').bind('click', function(e) {

                busy = true;    

                $('.loading-more').html('<em>Loading more posts..</em>')

                /* Quick message so you know more stuff is loading */               
                $.post('<?php bloginfo('siteurl') ?>/wp-admin/admin-ajax.php', {
                    action: 'and_action',
                    off: offset+number,
                    pagenumber: page_number,
                    query_string: '<?php echo $query_string; ?>'
                    }, function(data) {


                        offset = offset+number; 

                        $('.empty-div').append('<div class="pages"><p>Welcome to <strong>Page '+page_number+'</strong></p></div><hr />'+data);


                        busy = false;
                        page_number += 1;

                        $('.loading-more').html('Click to load more posts..');

                });


        });


    });
    </script>

The PHP function:

add_action('wp_ajax_and_action', 'get_posts_page');
add_action('wp_ajax_nopriv_and_action', 'get_posts_page');

function get_posts_page() {

$query_string = $_POST['query_string'];

global $wpdb;   


query_posts($query_string . '&posts_per_page=10&post_status=publish&offset='.$_POST['off']);    

if ( have_posts() ) : while ( have_posts() ) : the_post(); 


    ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
        <div class="entry-meta">

            <span class="%1$s">Posted on</span> <?php the_date('F jS'); ?>
            - <a class="comment-link" href="<?php the_permalink(); ?>#comment"><?php comments_number('Leave a Response!', '1 Response', '% Responses'); ?></a>
        </div><!-- .entry-meta -->
        <br />
        <a class="post-thumbnail-thing" href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail(); ?></a>            
        <div class="entry-content">
            <?php the_content( __( '<span class="alignright">
            <span class="button-css">Continue Reading &rarr;</span> 
             </span>', 'twentyten' ) ); ?><br /><hr />
            <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
        </div><!-- .entry-content -->
    </div><!-- #post-## -->

    <?php comments_template( '', true ); ?>

   <?php        
   endwhile; endif;
    die();

    }

header.php

<?php global $query_string; ?>

As I’ve said, the main problem is $query_string is null 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:02:55+00:00Added an answer on May 18, 2026 at 3:02 am

    Your globalizing $query_string inside of your header.php file, but you need to globalize it inside of your function javascript_page() inside of functions.php

    Here’s a video explaining what I’m doing

    function javascript_page() {
      global $query_string;
    ?>
    
    <script type="text/javascript">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.