Closed reardestani closed 11 years ago
Well... that'll definitely cause errors. The first method you're not actually getting the options from the database, so that's not going to work. Second method, you're trying to get the options from the database, but you're referencing the wrong thing. Redux_TEXT_DOMAIN is just that... a textdomain. Or, more accurately, a named constant representing your textdomain. I suggest taking a look at this if your are unfamiliar with that concept. What you should be doing is something like this...
$options = get_option('optname');
echo $options['my_option'];
where optname is whatever you have $args['opt_name']
set to in options.php and _myoption is the ID of an option.
Thanks for your response,
I did the following steps:
But, I get error in retrieving options. Where am I doing wrong?
For starters, you're misunderstanding what the textdomain does. It is a defined constant and should not be changed globally. All you need to do with it is change the initial definition in options.php if you want. As for your options issue... Does an option called example exist in the sections array?
I think I found my mistake. There is no need to change text_domain. The only thing that I have to change is value of $args['opt_name'] in options.php. I did the following and it works: $args['opt_name'] = "example";
To retrieve : $options = get_option('example'); echo $options['text_demo'];
Is it possible to put $options = get_option('example');
in a file like options.php and from then on use only echo $options['text_demo'];
.?
I do not want to rewrite $options = get_option('example');
whenever I retrieve an option.
In your functions.php (or another file that is called at the beginning of the init process), add $options = get_option('example')
like you normally would, but make $options a global. In other words...
global $options;
$options = get_option('example');
Then, you won't have to redefine $options everywhere.
I have done the following methods, but no resault.
To Test all the following methods, I added them at the top of the functions.php.
global $options; $options = get_option('shymarkets');
function redux_options(){ global $options; $options = get_option('shymarkets'); } add_action('wp_head', 'redux_options');
function redux_options(){ global $options; $options = get_option('shymarkets'); } add_action('init, 'redux_options');
Am I doing sth wrong again?
Any solutions?
You're not really showing me enough to judge... creating a global should work fine, so knowing how and where you're trying to use it would be really helpful.
Ok. the following codes are first lines of my theme functions,php.
<?php
/* Bootstrap the Theme Options Framework */ if ( file_exists( get_template_directory() . '/admin/options.php' ) ) require_once('admin/options.php');
function redux_options(){ global $options; $options = get_option('example'); } add_action('wp_head', 'redux_options')
if you use
$options = get_option('example');
then in setup_framework_options() function, you have to set
$args['opt_name'] = 'example';
just make sure there are redux options that were stored in your database. You can check WP_Options table:
SELECT * FROM WP_Options WHERE option_name LIKE 'example' --the opt_name value
sorry for my bad english
My problem is not the thing that you mentioned. My issue: I want to call
global $options; $options = get_option('example');once, then I can easily retrieve may options
echo $options['text_demo'];without redefining
global $options; $options = get_option('example');.
I hope it make sense.
if you copy your functions.php and options.php into http://pastebin.com/ it will be easier to see what you are trying to do and where your problems might be.
Ok.
Any luck with this? I too am having problems trying to define the options var globally, it only works when called right before the actual echo $options['text_demo'];
I could not solve it, so I am now using Default Wordpress Live Customizer. It is really great. Try to give it a try.
@ghost1227 could you weigh-in here, please?
if anyone is still interested, I wrote simple function that does what @reardestani asked for:
put this to functions.php
function my_option($selected_option) {
$options = get_option('example');
return $options[$selected_option];
}
now, wherever you want to pull an option in your theme just write:
echo my_option('text_demo');
instead of writing
echo $options['text_demo'];
hope that helps
I have implemented the latest version of framework with defaults options, but I can not retrieve options.
I have tried two methods:
Any solutions?