2013-01-23 2 views
-1

특정 사용자가 마지막 수정/크레이 튼 날짜를 게시 한 다음 에코하려고합니다.워드 프레스, SQL 데이터베이스에서 쿼리를 가져 와서 그것을 반향

난 할 노력하고있어입니다 :

<?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; ?> 

내 실수 어디에 있습니까? 누가 이것을 통해 나를 이끌 수 있습니까?

현재 $userModifiedDate1을 반환합니다.

답변

1

$wpdb->query()은 실제 쿼리 결과가 아닌 영향을받는 행 수를 반환합니다. 그것은 절대적으로 필요한을하지있는 동안 나는 항상 쿼리를 전달하고자,

$userModifiedDate = $wpdb->get_var($sql); 

http://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Variable

또한 :

http://codex.wordpress.org/Class_Reference/wpdb#Run_Any_Query_on_the_Database

같은 $wpdb->get_var() 또는 $wpdb->get_results()보다 구체적인 기능을 사용해보십시오 $wpdb->prepare() 통해 처음 :

http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks

+0

$sql = $wpdb->prepare("SELECT post_date FROM wp_posts WHERE ID = %d AND post_author = %d ORDER BY post_date DESC LIMIT 1", $postID, $userID); 
그것을 조금 형식에 설정을 몇 필요, 대단히 감사합니다, 그러나 그것은 나에게 많은 도움이! :) –

관련 문제