WordPress get sticky posts from database using $wpdb class

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.

Cheers

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

Leave a Reply

Your email address will not be published. Required fields are marked *