Display multiselect post values
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.
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);
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
Then use fw_get_db_post_option()
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);
?>
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);
thanks here is output .var dump returns null

ok got it .thanks
Thank Nice work , My problem is solve