Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

fw_get_db_post_option not working

Open xperter opened this issue 11 years ago • 19 comments

fw_get_db_post_option not working on my theme I have tried reinstalled again and check. i dont change anything from framework plugin but fw_get_db_settings_option work fine.

i have created custom function for get post meta. but still i wondering why fw_get_db_post_option not work for me. is there i need changed any settings. or i have doing any wrong.?

Thank you

xperter avatar Mar 07 '15 15:03 xperter

I added to {theme}/framework-customizations/theme/options/posts/post.php a test option

$options = array(
    // ...
    'test-box' => array(
        'type' => 'box',
        'options' => array(
            'test-option' => array('type' => 'text'),
        ),
    ),
);

and saved some post (with a value in test input). Then I added to {theme}/content.php this code

fw_print(
    fw_get_db_post_option(get_the_ID(), 'test-option')
);

and the value was printed in frontend.

ghost avatar Mar 07 '15 15:03 ghost

HI @moldcraft
here is my option with multipicker

$options = array(
    'page_sections' => array(
        'type' => 'multi-picker',
        'label' => false,
        'desc' => false,
        'picker' => array(
            'xp_page_section' => array(
                'label' => __('This page is a section:', 'xs'),
                'type' => 'switch',
                'right-choice' => array(
                    'value' => 'yes',
                    'label' => __('Yes', 'xs')
                ),
                'left-choice' => array(
                    'value' => 'no',
                    'label' => __('No', 'xs')
                ),
                'value' => 'no',
                'desc' => __('If its a Section, please set this field to on. And if its page, set it to off', 'xs'),
                'help' => sprintf("%s \n\n'\"

\n\n %s", __('If its a Section, please set this field to on. And if its page, set it to off', 'xs'), __('For One page always will be yes', 'xs') ), ) ), 'choices' => array( 'yes' => array( 'hide_title_from_menu' => array( 'type' => 'switch', 'label' => __('hide from menu', 'xs'), 'right-choice' => array( 'value' => 'yes', 'label' => __('Yes', 'xs') ), 'left-choice' => array( 'value' => 'no', 'label' => __('No', 'xs') ), 'value' => 'no', 'desc' => __('Show the Tile when set to yes, otherwise it will be hide from page', 'xs'), ), ), ), 'show_borders' => false, ), );

and i like to show data with

if (fw_get_db_post_option(get_the_ID(), 'hide_title_from_menu') != 'yes') {...}

really appreciate you help :)

Thank you

xperter avatar Mar 07 '15 16:03 xperter

@xperter

$options = array(
    'page_sections' => array(
        'type' => 'multi-picker', // ???
    ...

Is your option even visible on post edit page?

http://manual.unyson.io/en/latest/options/containers.html#restrictions

Post Options array on first level can have only box containers.

ghost avatar Mar 07 '15 16:03 ghost

Opss sorry i have removed unwanted code. i have deleted box code to. here is the options all

  array(
        'title' => false,
        'type' => 'box',
        'options' => array(
            'page_sections' => array(
                'type' => 'multi-picker',
                'label' => false,
                'desc' => false,
                'picker' => array(
                    'xp_page_section' => array(
                        'label' => __('This page is a section:', 'xs'),
                        'type' => 'switch',
                        'right-choice' => array(
                            'value' => 'yes',
                            'label' => __('Yes', 'xs')
                        ),
                        'left-choice' => array(
                            'value' => 'no',
                            'label' => __('No', 'xs')
                        ),
                        'value' => 'no',
                        'desc' => __('If its a Section, please set this field to on. And if its page, set it to off', 'xs'),
                        'help' => sprintf("%s \n\n'\"

\n\n %s", __('If its a Section, please set this field to on. And if its page, set it to off', 'xs'), __('For One page always will be yes', 'xs') ), ) ), 'choices' => array( 'yes' => array( 'hide_title_from_menu' => array( 'type' => 'switch', 'label' => __('hide from menu', 'xs'), 'right-choice' => array( 'value' => 'yes', 'label' => __('Yes', 'xs') ), 'left-choice' => array( 'value' => 'no', 'label' => __('No', 'xs') ), 'value' => 'yes', 'desc' => __('Show the Tile when set to yes, otherwise it will be hide from page', 'xs'), ), ), ), 'show_borders' => false, ), ), ), );

xperter avatar Mar 07 '15 16:03 xperter

Add this in your template

fw_print(
    fw_get_db_post_option(get_the_ID(), 'page_sections')
);

and inspect the multi-picker value.

ghost avatar Mar 07 '15 16:03 ghost

Hi Thanks for help. I have seen array now but how i can get value easily xp_page_section yes or no ?? i know i am bothering you. :) i am just create a theme for me.. and i love your framework but its quite complicated for me :D

Thank you

xperter avatar Mar 07 '15 17:03 xperter

I have seen array now but how i can get value easily xp_page_section yes or no ??

multi-picker values is a little confusing/weird.

array(
    'title' => false,
    'type' => 'box',
    'options' => array(
        'page_sections' => array(
            'type' => 'multi-picker',
            'label' => false,
            'desc' => false,
            'picker' => array(
                'xp_page_section' => array(
                    'label' => __('This page is a section:', 'xs'),
                    'type' => 'switch',
                    'right-choice' => array(
                        'value' => 'yes',
                        'label' => __('Yes', 'xs')
                    ),
                    'left-choice' => array(
                        'value' => 'no',
                        'label' => __('No', 'xs')
                    ),
                    'value' => 'yes',
                    'desc' => __('If its a Section, please set this field to on. And if its page, set it to off', 'xs'),
                ),
            ),
            'choices' => array(
                'yes' => array(
                    'hide_title_from_menu' => array(
                        'type' => 'switch',
                        'label' => __('hide from menu', 'xs'),
                        'right-choice' => array(
                            'value' => 'yes',
                            'label' => __('Yes', 'xs')
                        ),
                        'left-choice' => array(
                            'value' => 'no',
                            'label' => __('No', 'xs')
                        ),
                        'value' => 'yes',
                        'desc' => __('Show the Tile when set to yes, otherwise it will be hide from page', 'xs'),
                    ),
                ),
                'no' => array(
                    'test' => array('type' => 'text'),
                ),
            ),
            'show_borders' => false,
        ),
    ),
),
$sections = fw_get_db_post_option(get_the_ID(), 'page_sections');
fw_print(
    $sections[ $sections['xp_page_section'] ]
);

ghost avatar Mar 07 '15 17:03 ghost

i know i am bothering you. :) i am just create a theme for me.. and i love your framework but its quite complicated for me :D

No problem, we are here to help.

ghost avatar Mar 07 '15 17:03 ghost

still i cant access yes no value for hide_title_from_menu i receive array for xp_page_section how again i enter this array and grab the data for hide_title_from_menu yes no value :(

Thank you

xperter avatar Mar 07 '15 17:03 xperter

'hide_title_from_menu' is inside 'yes' value, 'hide_title_from_menu' does not exist in 'no' value.

P.S. After options array change, don't forget to save post to update database values.

ghost avatar Mar 07 '15 18:03 ghost

Yeap i understand but dont need xp_page_section value i like to get value from hide_title_from_menu yes or no $sections = fw_get_db_post_option(get_the_ID(), 'page_sections'); fw_print( $sections[ $sections['hide_title_from_menu'] ] );

here is my code which i like to use

if ( $sections[ $sections['hide_title_from_menu'] ] != 'yes') 
{.......}

if no condition will work

I dont do this kind of nested array before. thats y confused :(

Thank you

xperter avatar Mar 07 '15 18:03 xperter

  • $sections['xp_page_section'] contains yes or no
  • $sections[ $sections['xp_page_section'] ] contains 'choices'['yes'] or 'choices'['no']

try this

$picked_value = $sections[ $sections['xp_page_section'] ];

if ($sections['xp_page_section'] == 'yes') {
    fw_print('yes', $picked_value['hide_title_from_menu']);
} else {
    fw_print('no', $picked_value['test']);
}

ghost avatar Mar 07 '15 18:03 ghost

Thank you brother :+1:

xperter avatar Mar 07 '15 19:03 xperter

Brother i need little help again. i have created a simple shortocde

 'overlay_options' => array(
        'type' => 'multi-picker',
        'label' => false,
        'desc' => false,
        'picker' => array(
            'overlay' => array(
                'type' => 'switch',
                'label' => __('Overlay Color', 'fw'),
                'desc' => __('Enable image overlay color?', 'fw'),
                'value' => 'no',
                'right-choice' => array(
                    'value' => 'yes',
                    'label' => __('Yes', 'fw'),
                ),
                'left-choice' => array(
                    'value' => 'no',
                    'label' => __('No', 'fw'),
                ),
            ),
        ),
        'choices' => array(
            'no' => array(),
            'yes' => array(
                'background-image-overlay' => array(
                    'label' => __('Overlay', 'unyson'),
                    'type' => 'rgba-color-picker',
                    'value' => 'rgba(255, 0, 0, .5)',
                    'desc' => __('Lorem .', 'unyson'),
                    'help' => sprintf("%s \n\n'\"

\n\n %s", __('Lorem ', 'unyson') ), ) ), ), ),

i have tried to print rgba color but nothing work :(

$overlays = $atts['overlay_options']['overlay'];
if ($overlays == 'yes') {
    $overlay = $atts['overlay_options']['overlay']['background-image-overlay'];
}

Appreciate your help :) Thank you

xperter avatar Mar 08 '15 09:03 xperter

$overlays = $atts['overlay_options']['overlay'];
if ($overlays == 'yes') {
    $overlay = $atts['overlay_options'][ $overlays ]['background-image-overlay'];
}

ghost avatar Mar 08 '15 09:03 ghost

Its work for me. but i am receiving a undefined notice Notice: Undefined index: overlay_options in

is there i need to connect anything from options.php page ??

Thank you

xperter avatar Mar 08 '15 10:03 xperter

Inspect fw_print($atts)

ghost avatar Mar 08 '15 10:03 ghost

Here is the atts print details

array
(
    [overlay_options] => array
    (
        [overlay] => 'yes'
        [yes] => array
        (
            [background-image-overlay] => 'rgba(227,17,17,0.5)'
        )
    )
    [auto_generated] => ''
    [first_in_builder] => '1'
)

and after bottom of the section Notice: Undefined index: overlay_options in

array
(
    [auto_generated] => ''
)

xperter avatar Mar 08 '15 10:03 xperter

I don't think it's an Unyson issue/bug. Please inspect the arrays more carefully before accessing the keys.

ghost avatar Mar 08 '15 10:03 ghost