2017-04-12 56 views
0

我試圖使用自定義查詢從數據庫中獲取特定發佈信息(如果帖子是粘滯的)。

下面是該查詢:

"SELECT ID, post_title, post_author, post_date, option_value 
FROM `{$wpdb->prefix}posts`, `{$wpdb->prefix}options` 
WHERE post_status = 'publish' AND post_type = 'post' 
AND option_name = 'sticky_posts' 
ORDER BY post_date DESC LIMIT 2" 

但此查詢不起作用。它返回兩個帖子,但不是粘性的。

回答

1

好吧,算了一下。

我需要使用此代碼,檢查ID與AND ID IN ($stringSticky)

$sticky = get_option('sticky_posts');   
$stringSticky = implode(",", $sticky); 

$mostLatestPostsSticky = $wpdb->get_results(
    "SELECT ID, post_title, post_author, post_date 
    FROM `{$wpdb->prefix}posts` 
    WHERE post_status = 'publish' AND post_type = 'post' 
    AND ID IN ($stringSticky) 
    ORDER BY post_date DESC LIMIT $postlimit" 
); 
相關問題