is_page() conditional not working inside an AJAX function

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
    );

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

    if($type == 'latest'){

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

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

Related posts

Leave a Reply

1 comment

  1. 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.