• Hello
    I’m using ‘Admin Page Framework’ to administrate my theme, till now all is fine, but I’m straggling with the little documentation … and can’t list posts/pages from some reason (with select2) … what am I missing ?

    This code is taken from the demo, but is not working for me:

    <?php
    
            $this->addSettingFields(
    array(
        'type'          => 'select2',
        'field_id'        => 'pstSwiper_cat',
        'options'         => array(
            'minimumInputLength' => 2,
            'width' => '60%',
        ),
        'callback'        => array(
            'search'    => __CLASS__ . '::getPosts',
        ),
    ),
    
                array(
                    'field_id'      => 'pstSwiper_postno',
                    'title'         => __( 'No. of post to show', 'bitRT' ),
                    'type'          => 'no_ui_slider',
                    'default'       => 4,
                    'options'       => array(
                        'range' => array(
                            'min'   => 2,
                            'max'   => 10,
                        ),
                        'step'  => 1,
                    ),
                ),
    
                array( // Submit button
                    'field_id'      => 'submit_button',
                    'type'          => 'submit',
                    'value'         => __( 'Submit', 'bitRT' ),
                )
    
            );
    
    function getPosts( $aQueries, $aFieldset ) {
    
        $_aArgs         = array(
            'post_type'         => 'post',
            'paged'             => $aQueries[ 'page' ],
            's'                 => $aQueries[ 'q' ],
            'posts_per_page'    => 30,
            'nopaging'          => false,
        );
        $_oResults      = new WP_Query( $_aArgs );
        $_aPostTitles   = array();
        foreach( $_oResults->posts as $_iIndex => $_oPost ) {
            $_aPostTitles[] = array(    // must be numeric
                'id'    => $_oPost->ID,
                'text'  => $_oPost->post_title,
            );
        }
        return array(
            'results'       => $_aPostTitles,
            'pagination'    => array(
                'more'  => intval( $_oResults->max_num_pages ) !== intval( $_oResults->get( 'paged' ) ),
            ),
        );
    
    }
        new bitRT_Select2CustomFieldType( 'bitRT' );
     ?>
    
    • This topic was modified 4 years, 6 months ago by Tzvook.
    • This topic was modified 4 years, 6 months ago by Tzvook.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘list posts/pages with select2’ is closed to new replies.