Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138134

How to pass a php variable to an Wordpress AJAX call?

$
0
0

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!

I found something close to here: How to pass php variable to wordpress AJAX handler


Viewing all articles
Browse latest Browse all 138134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>