Thread Starter
reypm
(@reypm)
Ok, researching for a possible solution I’ve found this at demo.php file:
array(
'name' => __( 'Select', 'meta-box' ),
'id' => "{$prefix}select_advanced",
'type' => 'select_advanced',
// Array of 'value' => 'Label' pairs for select box
'options' => array(
'value1' => __( 'Label1', 'meta-box' ),
'value2' => __( 'Label2', 'meta-box' ),
),
'multiple' => false,
'placeholder' => __( 'Select an Item', 'meta-box' ),
)
Now, how do I get all the post from the DB?
To get all post from DB, you can use this code:
$posts = get_posts( array(
'post_type' => array( 'post', 'page' ), // Add your post types here
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
) );
$options = array();
foreach ( $posts as $post )
{
$options[$post->ID] = $post->post_title;
}
Then you can pass $options to the field like this:
array(
'name' => __( 'Select', 'meta-box' ),
'id' => "{$prefix}select_advanced",
'type' => 'select_advanced',
// Array of 'value' => 'Label' pairs for select box
'options' => $options,
'multiple' => false,
'placeholder' => __( 'Select an Item', 'meta-box' ),
)
Thread Starter
reypm
(@reypm)
Hi, excellent but because I have a lot of post this option is not suitable for me since page get too slow which leads me to the next question, can I do the same using Select2 Ajax functionality? How?
Right now the plugin doesn’t support ajax functionality for Select2. But it’s put on the issue list on Github and we will try to implement it later.
Thread Starter
reypm
(@reypm)
Ohhh nice but later you mean today or other day? I need this as soon as you can, any ETA?
The time isn’t specified yet. I hope we can implement it in next major version update.