Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

 
discard

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.