WordPress.org

Ready to get started?Download WordPress

Forums

what if i will try to add option which already exists? (3 posts)

  1. kkarpieszuk
    Member
    Posted 4 years ago #

    hello, i have question about add_option() function

    what will heppen when i will try to add option, which already exists? will wordpress engine just update this option or will do nothing?

    i ask because i wonder if it is neccesary to write smth like that:

    if (!get_option('optname')) add_option('optname', 'optvalue');
    else update_option('optname', 'optvalue');

    ?

  2. MichaelH
    Member
    Posted 4 years ago #

    According to Function_Reference/add_option

    A safe way of adding a named option/value pair to the options database table. It does nothing if the option already exists.

  3. kkarpieszuk
    Member
    Posted 4 years ago #

    Michael, thank you.

    But in other hand: what will heppen if i will try to update option if this option doesn't exists? Will it be created or just nothing heppen?

Topic Closed

This topic has been closed to new replies.

About this Topic