How I could made a sql query who retrieve all the sticky post in a wordpress database? This is because we use a new app over the old wordpress website database, and I don't know where Wordpress "store" the sticky attribute.

Thanks in advance


It's not stored as attribute, but as list of all stickies. Snippet from core:

$sticky_posts = get_option('sticky_posts');

So look for the option and then use IDs to retrieve posts.

  • But inside the database is stored in some form, no? I can't use the php code, because I have only the database, so I only could use sql.
    – Mangano
    Jun 28 '11 at 21:22
  • @Nisanio it's in option, so look in options table (wp_options or whatever your db has)
    – Rarst
    Jun 28 '11 at 21:27

In raw SQL it would look like this:

SELECT option_value FROM `wp_options` where option_name = 'sticky_posts'

It will return string similar to:


Which means that posts with IDs: 27935 and 33322 are "sticky". If there are no sticky posts the returned string will look as follows:


For more details about Wordpress serialized data structure view https://codex.wordpress.org/Function_Reference/maybe_serialize

Anyway if you are developing custom theme or plugin it's much better to use snippet provided by @Rarst than writing custom queries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.