2

I'm creating a wordpress theme in which I'm using the Redux Framework for creating the theme's options page. Now I believe everything is well set up but I'm having trouble in getting the values changed by Redux in my front end.

For example I checked one of the checkbox in the settings panel had this attribute: name="redux_demo[10]", so in my front end I did this:

    <?php 
    if(get_option('redux_demo[10]')) { ?>  

      <h1>Text</h1>  

    <?php 
    }?>

But Text is not showing whether I save it as checked or unchecked. I also tried the following but it's also not working:

    <?php 
    if(get_option('redux_demo[10]') === 1) { ?>

      <h1>Text</h1>  

    <?php 
    }?>

I searched a lot in the docs and also on the internet but I can't find any tutorial that shows how to actually retrieve data saved by redux. Please let me know if you have any idea about this.

Thank you very much.

3

I have no idea how the framework actually stores its options, but I guess it uses the name redux_demo, not redux_demo[10]. If the option is an array, you can access the element 10 like this:

$redux_demo = get_option( 'redux_demo' );

if ( ! empty ( $redux_demo[ 10 ] ) and 1 === $redux_demo[ 10 ] )
{
    print '<h1>Text</h1>';
}
  • 1
    Don't do it this way as we've already grabbed this data for you and placed it in a global variable. Don't waste precious DB resources. ;) – Dovy Jun 9 '14 at 6:29
  • 1
    @Dovy get_option() calls are cached, no DB query will be harmed by my solution. :) On the plus side it doesn’t use a global variable—something you should never do anyway. – fuxia Jun 9 '14 at 10:53
  • And why not? heh. Yea, the DB may be cached, but you still have to run another function. The global variable is wide open and has already been set. – Dovy Jun 9 '14 at 17:00
  • 1
    @Dovy The global variable can be changed any time by any code, and it makes the consuming code untestable. This is why you won’t find global variables in modern PHP code. – fuxia Jun 9 '14 at 18:57
1

Redux actually stores your saved settings in a global variable which is established in your redux config file (public function setArguements) under opt_name, in this case $redux_demo. You can choose which option you want to display by referencing the unique ID of that option. Here's an example:

<?php
global $redux_demo;
if( $redux_demo['10'] === 1 ) { ?>
    <h1>Text</h1>
<?php } ?>

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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