1

When using posts there is a way to store meta values on a per post level. Is there a way to store values on a global site value? I want to save a numeric value that isnt tied to any single post.

I was thinking i could just do something like

get_post_meta( 0, 'somevalue', true );

This will work, but it will still be storing the value as a post field. is there anything specific that was designed for this

1 Answer 1

3

Yes there is Option API to store site global data.

You can store some global values using add_option() then can retrive values as get_option()

Example:

add_option( 'option_name', 'option_value', 'deprecated', 'yes' );
//OR
update_option('option_name', 'option_value', 'yes');


//Get the value
$your_data = get_option('option_name', 'option_default_value');
echo $your_data;
2
  • i am in a position where i will need to be creating one new field a day and adding onto it as the day goes on. will calling update create a field if it does not exist already? Commented Apr 11, 2016 at 10:16
  • 1
    Yes, exactly if field does exist it calls add_option().
    – Sumit
    Commented Apr 11, 2016 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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