I have 7 pages about services.
In documentation of Redux Framework explain the class select
and multi select
Example Multi Select code:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
//Must provide key => value pairs for radio options
'options' => array(
'1' => 'Opt 1',
'2' => 'Opt 2',
'3' => 'Opt 3'),
'default' => array('2','3')
);
How I do for in options
insert dynamically all pages ids or posts ids registered in DB?
UPDATED
Redux::setSection($opt_name, array(
'id' => 'options_services',
'title' => 'Services',
'subsection' => true,
'fields' => array(
array(
'id' => 'opt-multi-select_pages',
'type' => 'select',
'multi' => true,
'title' => 'Multi Select Option',
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('1','2','3','4','5')
)
)
));
index.php
<?php
foreach ($global_master['options_services'] as $singleValue){
?>
<div class="col-md-6 col-sm-6">
<div class="service-item">
<h4> <strong><?php echo $singleValue['post_title'] ?> </strong></h4>
<img src="<?php echo $singleValue['post_thumbnail_url'] ?>" alt="..." class="img-thumbnail img-responsive">
<a href="<?php echo $singleValue['guid'] ?>" class="btn btn-light">See More</a>
</div>
</div>
<?php
}
?>
The above code does not return anything in the index
In the code I Try use returns 'post_title' and 'guid' indicated in documentation wordpress and not have references of 'post_thumbnail_url.'
UPDATED 2
I was able to solve my initial doubt with the help of Nathan Dawson and to print I used the code below:
<?php
foreach ($global_master['opt-multi-select_pages'] as $singleValue){
$post_thumbnail_id = get_post_thumbnail_id($singleValue);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
?>
<div class="col-md-6 col-sm-6">
<div class="service-item service">
<h4> <strong><?php echo get_the_title($singleValue); ?> </strong></h4>
<img src="<?php echo $post_thumbnail_url; ?>" alt="..." class="img-thumbnail img-responsive">
<a href="<?php the_permalink($singleValue); ?>" class="btn btn-light">See more</a>
</div>
</div>
<?php
}
?>
Fields in the Redux Framework have the option to dynamically list pages out of the box, you simply need to set the argument. Drop 'options' and set a value for 'data' instead.
Example:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('2','3')
);
You may notice I've also added the 'args' option. The pages 'data' option will retrieve 20 by default, the custom args retrieve all pages instead.
Documentation: https://docs.reduxframework.com/core/the-basics/using-data-argument/