Wordpress Posts not loading through AJAX using WPML

I have a news page where posts are dynamically loaded based upon which category in the menu is clicked. This is done through Javascript/AJAX. The site is multi language and I'm using WPML to switch between languages. This works absolutely fine everywhere on the site, but as soon as I try to exclusively echo posts from the other language through AJAX, it doesn't work.

It displays absolutely nothing even if the category ID is correct.

The code I am using in AJAX is as follows;

query_posts( array('posts_per_page' => $posts, 'paged' => 1, 'category__in' =>   $selectedCategory, 'lang' => $curLang));

Now I've tested if the current language was not being parsed correctly, but even statically putting in 'en' didn't change a thing, it still wouldn't echo the english posts through Ajax. The code however works fine in a regular old PHP file.

The javascript I'm using to fill the variables in to pass to AJAX is as follows:

var load_posts = function(postMax, category){ 
        $.ajax({  
            type       : "POST",  
            dataType   : "html",  
            url        : siteurl + "ajax/?postMax="+postMax+"&numPosts=6&pageNumber="+page+"&category="+category+"currentLang="+curLang,  
            beforeSend : function(){ 
            },  
            success    : function(data){  

                if(page <= 6){
                    content.empty();
                    content.append(data);  
                    $('.more-link').each(function(){
                        var tempLink = $(this).attr('href');
                        $(this).parent().parent().parent().parent().children('a').attr('href', tempLink);
                    });
                    loading = false;  
                    if(page === 3){
                        $('#nieuwsContent').css("padding-top", "10px");
                    }
                    page++;
                }
            },  
            error     : function(jqXHR, textStatus, errorThrown) {  
                alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);  
            }  
        });  
    };  

I'm at a complete loss as to what I should be doing to fix this.

Answers


Could the issue be in the rendered URL for the AJAX request? Looks like it's missing a '&' symbol before the 'currentLang' field.

e.g '&category="+category+"currentLang="+curLang', should be '&category="+category+"&currentLang="+curLang'


Need Your Help

What makes a gem incompatible with JRuby?

ruby gem bundler jruby

I ran bundle install and to my surprise, most of the gems that ship with Rails 4 installed just fine. byebug was one that did not, but no big deal.

asp.net app not drawing lines when on web server

c# asp.net drawing webserver

I have been working on an asp.net webapp that draws a blue line on an image of a time-schedule depending on what activity you are doing during the day . Everything works fine when I'm debugging the