Sending PHP variables with ajax and then displaying a mysql query result -
This question may be asked already. But I could not figure out how to do this.
Therefore .. in the URL, I have example.com/get-coupon.php?id=288 This is a custom post type post id in WordPress
What do I want to do I'm sending this ID in another file, which makes this DB query using this ID to return the code.
My current get-coupon.php:
& lt; Script src = "// code.jquery.com/jquery-1.11.0.min.js"></script> & Lt; Button id = "getcode" & gt; Get your code & lt; / Button & gt; & Lt; Div id = "resultip" & gt; & Lt; / Div & gt; & Lt; Script & gt; Click $ ('# Getcode') (function (e) {var pID = '& lt ;? php $ _GET [' id ']? & Gt;' $. $ Xxxx ({type: 'POST', url: 'Coupon .php', data: {id: pID}, success: function (feedback) {content.html (id);}})}}; & Lt; / Script & gt;
and my coupon.php
$ id = $ _GET ['id']; / ** WordPress loads the environment and templates * / global $ wpdb, $ wp_query; ('Wp-load.php'); $ Id = $ _GET ['id']; $ Args = array ('post_type' = & gt; 'coupon', 'p' = & gt; $ id); $ Loop = new WP_Query ($ Args); $ Coupon = get_post_meta ($ post-> ID, 'clpr_coupon_code', true); $ Coupon per coupon;
And then, I want to send the ID variable to the query file from the URL.
Comments
Post a Comment