WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a jQuery ui tabs that load posts via ajax on sidebar. Now in a specific page i want to filter the query post via is_page(); conditional. But in my case its not working.

function load_home_classifieds($type){

    $query = array(
        'post_type' => 'classified',
        'posts_per_page' => 5

            //echo 'ok';
            $query['tax_query'] = array(
                                            'taxonomy' => 'classified-category', 
                                            'field' => 'slug', 
                                            'terms' => array( 'real-estate' ),
                                            'operator' => 'NOT IN'

    if($type == 'latest'){

        get_template_part('loop', 'cfhome'); 
    elseif($type == 'random'){
        $query['orderby'] =  'rand';
        get_template_part('loop', 'cfhome'); 
        echo 'Invalid request!';        

Now, my question is how to get the conditional working inside an ajax function?

share|improve this question
up vote 3 down vote accepted

If this is executed within an ajax request, is_page() won't be set. the page you're making the request from was a previous request. you need to set something on the originating page to pass with your ajax request to let it know it's for your special case page.

share|improve this answer
Thanks! had to set a get variable and check in ajax function for it to make it work. – Sisir Aug 21 '11 at 16:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.