1

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

1

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. – Nisanio 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
2

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:

a:2:{i:0;i:27935;i:1;i:33322;}

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

a:0:{}

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.