How to pass a php variable to an WordPress AJAX call?
-
I have embeded a post (CPT) by a shortode. So I get the output of this post on a page, where I want to filter the content of this embeded post by AJAX. That would work, if I could send the ID of this embeded post in the ajax call.
I get the ID of the embeded post from a shortcode [documentlist listid=”2126″].
$atts = shortcode_atts( array( 'listid' => '', ), $atts ); $posts = array( 'post_type' => 'documentlist', 'page_id' => $atts['listid'], );
So I have this $atts[‘listid’] variable. How can I add this to the following ajax code (which is in an diffeent scripts.js file)?
/*The ajax call*/ jQuery(function($){ $('#filter #documenttypefilter, #filter #applicationareasfilter').change(function(){ var filter = $('#filter'); var serializedFilter = filter.serialize(); $.ajax({ url:filter.attr('action'), data:filter.serialize(), // form data type:filter.attr('method'), // POST success:function(data){ $('#response').html(data); // insert data } }); return false; }); });
Thanks so much for your help!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to pass a php variable to an WordPress AJAX call?’ is closed to new replies.