I am currently working on a plugin, and I want to add a settings page. I've already found out how to create the settings page, but how do I get the content from the settings page into a variable so I can use it?
2 Answers
In your options page each field should be put into an options array. For Example:
When you registered your settings page you should have used a code like this:
register_setting( 'pluginPage', 'rt_fed_settings', 'rt_validate');
Once on your page where you want to call settings, use this code:
$options_fed = get_option('rt_fed_settings'); // this is calling your settings array into a variable called options_fed.
Now to call items from it you would call them just like any array items:
$options_fed['rt_fed_text_test_billing_field']
The array items were set in your plugins page, but if you want see what is in the code you can use print_r.
-
I used
register_setting("member_only_fields", "loginURL");
, so what would I use?options = get_option("member_only_fields")
then$options["loginURL"]
doesn't work Aug 14, 2017 at 18:53 -
-
It returns nothing, but when I return to the settings page, it's still there, so its saving. Aug 14, 2017 at 18:55
Turns out it a lot simpler than I though. When you use register_setting("something", "name")
then to get it in the plugin, just use get_option("name")
.