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 created a lazy loading script using AJAX and JSON for my blog. It works perfectly. However I have 4 different blogs on the same site. These are created using custom post types.

I need to get the AJAX to do lazy loading for all of these blogs. I can get it to work for each one by manually changing the name from post to boutiques for example.

So I created a variable called $postname and want to assign this a different value depending on the slug of the page you are on when you click load more posts.

How can i check what page slug is and then assign my variable a name. Here is my code but I need to know how to call the slug of the page im on and assign that to $slug.

if ( $slug == 'boutiques'  ) {

    $postname = 'boutiques';

} elseif ( $slug == 'tourist' ) {

    $postname = 'tourist';
else {
    $postname = 'post';
share|improve this question

assuming you are properly adding the AJAX script to your theme via wp_enqueue_script, you can pass data to the script via wp_localize_script, which you should already be using to pass the path to admin-ajax.php if you are using AJAX correctly within your plugin or theme.

see the Codex page on AJAX for more info. this tutorial linked at the bottom of that page has all the examples you'll need.

a purely javascript solution (which I don't recommend) would be to use the location object to determine context.

share|improve this answer

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.