I’m trying to use a custom query to get specific post info from the database if the posts are sticky.

Here is the query:

"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"

But this query does not work. It returns two posts but not the sticky ones.
Anyone know how to fix this.


Read more here: WordPress get sticky posts from database using $wpdb class


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: