2268 posts
  • Power Elite Author
  • Author Level 12
  • Exclusive Author
  • Winner
+16 more
mpc
says

Hi guys, as always while developing new theme I run into a problem. I have a slider and the slides for this slider are defined as custom posts. Each of the slides has custom additional settings (using custom meta box for this). As a slider engine I use the jQuery Slides.

For example one of the parameter for each slides is background color. When the slide changes I need to get the post id, I use the get_post_custom to read the custom meta data and then change with jQuery the background color, the only problem is that I cannot get the current post ID inside the PHP because all the posts are already on the page, hidden… I have an idea how to get the post ID inside the jQuery but again how to send it back to PHP ? ;/ Any help would be appreciated…

P.S Is really GET my only option? ;/ I hate this…

2268 posts
  • Power Elite Author
  • Author Level 12
  • Exclusive Author
  • Winner
+16 more
mpc
says

I am seriously stuck :/ Any help would be great…

1908 posts YOU TOUCH IT YOU BUY IT
  • Copyright Ninja
  • Most Wanted Winner
  • Top Monthly Author
  • Community Superstar
+12 more
FRESHFACE
says

Hi!

here you can read how to handle ajax requests in WP: codex.wordpress.org/AJAX_in_Plugins

and for sending these requests, I personally use jQuery.post function.

hope I helped a lil bit :)

cheers, freshface

19 posts
  • Weekly Top Seller
  • Elite Author
  • Featured Author
  • Exclusive Author
+5 more
DesignerThemes
says

If you’re able to grab the ID with JavaScript, you can send it back to PHP with something like this:


//Get the ID from the HTML somewhere
var post_id = '10';

$.post('path/to/php/file.php', { 
     id: post_id
}, function(data)
     //Do something when completed
     console.log(data);
});

Then in your PHP file you would have this:

$id = $_POST['id'];

Hope that helps.

2268 posts
  • Power Elite Author
  • Author Level 12
  • Exclusive Author
  • Winner
+16 more
mpc
says

Hi, guys I have done something else I have put all the data for my slides inside a PHP array and passed this array into JS I think this is the easiest solution ;)

by
by
by
by
by
by