I want to get post last modification/craetion dates by particular users and then echo it.
What I’m trying to do is:
<?php $id = get_the_ID();
global $current_user;
$current_user = wp_get_current_user();
$postID = $id; //assigning post id
$userID = $current_user->ID; // assigning user ID
$sql = "SELECT post_date FROM wp_posts WHERE ID = $postID AND post_author = $userID ORDER BY post_date DESC LIMIT 1";
$userModifiedDate = $wpdb->query($sql);
echo $userModifiedDate; ?>
Where is my mistake? Can anyone lead me through this?
At the moment $userModifiedDate returns me 1.
$wpdb->query()returns the number of rows affected rather than the actual query result.http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database
Try using a more specific function such as
$wpdb->get_var()or$wpdb->get_results():http://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Variable
Also, while it’s not absolutely necessary, I always like to pass any queries through
$wpdb->prepare()first:http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks