WordPress.org

Ready to get started?Download WordPress

Forums

query_posts() returning same results with ajax (8 posts)

  1. David Powell
    Member
    Posted 3 years ago #

    I have a page that that is run on ajax. When the user selects to see older posts jquery calls the load() function and loads the next set of posts in a specified section.

    my jquery:

    jQuery('.moreButton a, .backButton a').live('click', function(e){
            e.preventDefault();
            var link = jQuery(this).attr('href');
            jQuery('.blogDisplay').fadeOut(200).load(link + ' .blogDisplay', function(){ jQuery('.blogDisplay').fadeIn(800); makeThumb();});
          });

    the section I have in the index:

    <?php
                    query_posts('cat=-132');
                    if (have_posts()):?>
                <?php while (have_posts()) : the_post(); ?>

    when the page loads first it shows the correct set of posts. when I choose to see the next set it always shows the same first set. However, when I remove the change in query_posts() to show all the posts it woks perfectly.

    Any ideas?

    [Bump deleted - They're not allowed on these forums - MOD.]

  2. You mean when you remove cat=-132 it works?

    What happens if you tell it something positive, like cat=132? Just for a test to see where it's breaking.

    Also, does it work without your ajax code?

  3. David Powell
    Member
    Posted 3 years ago #

    problem persists on a positive number too.

    I can't test it without the ajax. The page is almost finished and causes issues when that portion is removed.

    I've even tried

    $blogPost = new WP_QUERY();
    $blogPost->query(array('category_name'=>'blog'));
    if ($blogPost->have_posts()):
    
    while($blogPost->have_posts()) : $blogPost->the_post()

    and

    $blogPost = new WP_QUERY();
    $blogPost->query(array('category__not_in'=>'-132'));
    if ($blogPost->have_posts()):
    
    while($blogPost->have_posts()) : $blogPost->the_post()
  4. Can you make a second page without the ajax to test? Really I want to exclude it, since it works fine on my set up that way, so logically it's either the ajax, the theme or a plugin. Gotta eliminate them to know what we're up against.

  5. David Powell
    Member
    Posted 3 years ago #

    I can try setting up a test location. I created the theme and the ajax for it. Works great except for that one line. If I remove the query_posts('cat=-132') line it works perfectly.

  6. David Powell
    Member
    Posted 3 years ago #

    if I remove
    query_posts('cat=-132') in the index and add
    link = link+"?cat=-132"; to the jquery
    I can get the next set of page correctly. I only have the issue when it's on the index page.

  7. David Powell
    Member
    Posted 3 years ago #

    i found a workaround

    I added some javascript that replaces the blog content when it loads. So the page loads showing all the posts, then the javascript takes over and replaces it with the first page of what I want to be there:

    $(function()
      {
    		link = "http://www.mordantworld.com/?cat=-132";
    		jQuery('.blogDisplay').fadeOut(200).load(link + ' .blogDisplay', function(){ jQuery('.blogDisplay').fadeIn(800); makeThumb();});
    	});
  8. Okay, then LIKELY the problem is(was) that the JS/Ajax combo was stripping things :/ Since link +?cat... is what the query SHOULD be putting in.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.