I want to get data(time) by comparing userid and date against a post.
data stored in this form.
meta key
date - 03-01-2017
time - 5AM-6AM
userid - 1
Now when I click on a button I get the date and userid.
$(".date").click(function(){
clicked = this;
var dates= $(clicked).closest("ul").find(".getdate").val();
var item= jQuery(this).closest("li.lia");
var date = jQuery(item).find("input.getdate").val();
alert(date);
$.ajax({
type: 'POST', // Adding Post method
url: MyAjax.ajaxurl, // Including ajax file
data: {"action": "date_time", "date":date,
"userid":'<?php echo $uid;?>'}, // Sending data dname to post_word_countfunction.
success: function(data){ // Show returned data using thefunction.
alert(data);
}
});
});
Then I send this data through ajax to a function date_time.
function date_time(){
$date = $_POST['date'];
$userid = $_POST['userid'];
global $wpdb;
$sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'date' AND meta_value='$date' AND meta_key = 'userid' AND meta_value='$userid'";
$results = $wpdb->get_results($sql) or die(mysql_error());
print_r($results);
}
here I match userid and date and try to get time but it is showing 0 in alert of ajax success function.
meta_key = 'date'andmeta_key = 'userid'(which is what you're requesting). Can you be clearer as to how the data is stored? Is it three rows in$wpdb->postmeta, one for user, one for date, and one for time?