Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用$wpdb类从数据库获取粘性文章_Mysql_Wordpress_Custom Wordpress Pages - Fatal编程技术网

Mysql 使用$wpdb类从数据库获取粘性文章

Mysql 使用$wpdb类从数据库获取粘性文章,mysql,wordpress,custom-wordpress-pages,Mysql,Wordpress,Custom Wordpress Pages,我试图使用自定义查询从数据库中获取特定的帖子信息,如果帖子是粘性的 以下是查询: "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' O

我试图使用自定义查询从数据库中获取特定的帖子信息,如果帖子是粘性的

以下是查询:

"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"
但这个查询不起作用。它返回两个帖子,但不返回粘性帖子。

好的,我知道了

我需要使用此代码,并检查带有
的id和($stringSticky)
中的id:

$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"
);