2176 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator 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…

2176 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

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

1860 posts YOU TOUCH IT YOU BUY IT
  • Bought between 100 and 499 items
  • Referred between 200 and 499 users
  • Has been a member for 4-5 years
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
+1 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
  • United States
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Bought between 1 and 9 items
  • Referred between 500 and 999 users
  • Has been a member for 2-3 years
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.

2176 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator 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