That video web guy That video web guy - 2 months ago 17
PHP Question

Wordpress customizer (kirki) page list / sortable

I'm trying to put in place a sortable field where the options value are the page titles,

I'm using Kirki plugin,

How can i do that ?

here's is the code
Thanks a lot for your time

Using theme_mods or options?

theme_mods

Code to reproduce the issue (config + field(s))

<?php
$pages = get_pages();
foreach ($pages as $page ) {
$pages_list[] = array ('id' => $page->ID, 'title' => $page->post_title);
};
print_r($pages_list);

Kirki::add_field( 'my_config', array(
'type' => 'sortable',
'settings' => 'my_setting',
'label' => __( 'This is the label', 'my_textdomain' ),
'section' => 'my_section',
'default' => array(
'option3',
'option1',
'option4'
),
'choices' => $pages_list,
'priority' => 10,
) );
?>

Answer

got it !

$pages_array = array();
$get_pages = get_pages( 'hide_empty=0' );
foreach ( $get_pages as $page ) {
    $pages_array[$page->ID] = esc_attr( $page->post_title );
}

Kirki::add_field( '_s_theme', array(
    'type'        => 'sortable',
    'settings'    => 'sort',
    'label'       => __( 'This is the label', 'my_textdomain' ),
    'section'     => 'sections',
    'default'     => array(),
    'choices'     => $pages_array,

    'priority'    => 10,
) );