I'm trying to do a database query that will return the meta_value of a particular row in the postmeta table based on the post ID. Then pass the variable as an integer to a jQuery variable. Here's what my code looks like:
function getListings() {
var value3 = jQuery("#input_1_3").val();
if (value3 === 'something') {
value3 = <?php echo $wpdb->get_var( "SELECT meta_value
FROM $wpdb->postmeta WHERE post_id = 11" );
?>;
}
}
Right now it's returning a weird series of numbers and a ";"...The result I need should be an integer.
Any help would be greatly appreciated. I'm sure it's something obvious, but don't know what.
UPDATED:
Here is a screenshot of one of the tables I'm trying to get a meta_value from. The value I want to retrieve is "5".
I would strongly recommend using the built-in WP function get_post_meta:
NOTE: You need a "key" when doing this - what value are you hoping to return? You're going to get multiple values unless you define a key:
function getListings() {
var value3 = jQuery("#input_1_3").val();
if (value3 === 'something') {
value3 = <?php echo get_post_meta(11, 'my_key', TRUE) ?>;
}
}
Based on your edits, it looks like the key is pack_listings
, so the code would be as follows:
function getListings() {
var value3 = jQuery("#input_1_3").val();
if (value3 === 'something') {
value3 = <?php echo get_post_meta(11, 'pack_listings', TRUE) ?>;
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments