WordPress.org

Ready to get started?Download WordPress

Forums

Sticky Post (8 posts)

  1. philaecom
    Member
    Posted 3 years ago #

    Hi I need to use some of the data in my wordpress database. Wondering when looking at Database how can I find out if a post is sticky or not. I don't see an obvious field

  2. jomsky
    Member
    Posted 3 years ago #

    is_sticky( '17' )
    Returns true when Post 17 is considered a sticky post.
  3. philaecom
    Member
    Posted 3 years ago #

    @jomsky where would i see in the MySQL database. Lets say I need to find all Sticky post because i'm using it in an application outside of wordpess?

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    do a database search for 'sticky' - this should lead you to the 'options' table; column: option_name; row: sticky_posts

    http://codex.wordpress.org/Database_Description#Table:_wp_options

    example:

    $sticks = $wpdb->get_results("SELECT * FROM $wpdb->options WHERE option_name = 'sticky_posts'");
    
    $stickies = unserialize( $sticks[0]->option_value ); //array with the IDs of sticky posts
  5. philaecom
    Member
    Posted 3 years ago #

    @alchymyth thanks for your help found it.

  6. Mark / t31os
    Moderator
    Posted 3 years ago #

    The correct way to fetch the sticky data would be to call get_option which will deal with serialization for you.

    $sticky_posts = get_option( 'sticky_posts' );

    Ultimately, both should do the same thing though.

  7. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    @Mark - thank you - there is always something new to learn ;-)
    i was not aware that get_option() does exactly this.

  8. Mark / t31os
    Moderator
    Posted 3 years ago #

    WordPress does this in various areas using maybe_serialize and maybe_unserialize.
    http://codex.wordpress.org/Function_Reference/maybe_serialize
    http://codex.wordpress.org/Function_Reference/maybe_unserialize

    Those functions are used in various areas of WP, users need not serialize and unserialize data, the WordPress functions tend to do this where appropriate, on updating and retrieval.

    Serialization only occurs with arrays and objects though, strings are left alone.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.