Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Display multiselect post values

Open webangon opened this issue 12 years ago • 8 comments

Hi again .I was digging into the framework .I was unable to display the corresponding posts.

'demo_multi_select_posts_2' => array(
    'type' => 'multi-select',
    'label' => __('Multi-Select: Posts', 'fw'),
    'population' => 'posts',
    'source' => 'post',
    'desc' => __('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'fw'),
    'help' => sprintf("%s \n\n'\"<br/><br/>\n\n <b>%s</b>",
        __('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'fw'),
        __('Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium', 'fw')
    ),
),

To display the posts I have tried in view.php

<?php echo do_shortcode( $atts['demo_multi_select_posts_2'] ) ?>

But it returns array I guess as I have this warning WARNING: STRPOS() EXPECTS PARAMETER 1 TO BE STRING, ARRAY GIVEN IN C:\WAMP\WWW\EEE\WP-INCLUDES\SHORTCODES.PHP ON LINE 196

How this works I mean does it returns the id's of post?

Edit: To inspect element I used <?php var_dump(['demo_multi_select_posts_2']); ?> but it does not return the result.

webangon avatar Nov 05 '14 18:11 webangon

Hi,

<?php echo do_shortcode( $atts['demo_multi_select_posts_2'] ) ?>

What shortcode you tried to do there?

<?php var_dump(['demo_multi_select_posts_2']); ?>

I think you use the php 5.4 arrays. That line of code is equivalent with <?php var_dump(array('demo_multi_select_posts_2')); ?>


Option type multi-picker saves its value as array. In your case it will be post ids array(15, 32, 7).

To get posts by id, use get_posts()

$posts = get_posts(array(
    'include' => fw_get_db_settings_option('demo_multi_select_posts_2')
));

fw_print($posts);

ghost avatar Nov 05 '14 18:11 ghost

Thank you.I am using this in page builder (shortcodes) so I thinkfw_get_db_settings_option will not work .fw_get_db_settings_option is for theme settings but I am using this on page builder.I am using here framework-customizations/theme/shortcodes/team-member/options.php and to display framework-customizations/theme/shortcodes/team-member/views/view.php

webangon avatar Nov 05 '14 19:11 webangon

Then use fw_get_db_post_option()

ghost avatar Nov 05 '14 20:11 ghost

This code returns all posts not the selected.

$posts = get_posts(array(
    'include' =>  fw_get_db_post_option('demo_multi_select_posts_2')
));

fw_print($posts);
?>

webangon avatar Nov 05 '14 20:11 webangon

You are using wrong the fw_get_db_post_option() function. As first argument it takes the post id, then the option id.

global $post;

$ids = fw_get_db_post_option($post->ID, 'demo_multi_select_posts_2');

fw_print($ids);

$posts = get_posts(array(
    'include' => $ids
));

fw_print($posts);

ghost avatar Nov 05 '14 20:11 ghost

thanks here is output .var dump returns null untitled

webangon avatar Nov 05 '14 21:11 webangon

ok got it .thanks

webangon avatar Nov 05 '14 22:11 webangon

Thank Nice work , My problem is solve

alaminsobuj avatar Sep 28 '17 20:09 alaminsobuj