How to paginate information obtained from a query to a custom table?


I am building a small application which consults a registration group of a bd in wordpress, the code is as follows.

function opt_menu_cactaceas() {
    global $wpdb;
    $tabla_aspirantes = $wpdb->prefix . 'cactaceas2';
    echo '<div class="wrap"><h1>Lista de aspirantes</h1>';
    echo '<table class="wp-list-table widefat fixed striped">';
    echo '<thead><tr><th width="70%">Nombre Cientifico</th><th width="30%">Imagen</th></tr></thead>';
    echo '<tbody id="the-list">';
    $aspirantes = $wpdb->get_results("SELECT * FROM $tabla_aspirantes");
    foreach ( $aspirantes as $aspirante ) {

        $genero = esc_textarea($aspirante->genero);
        $especie = esc_textarea($aspirante->especie);
        $subespecie = esc_textarea($aspirante->subespecie);
        $autor = esc_textarea($aspirante->autor);

        if ( $subespecie == '' ):

            $nombreCactacea = "<i>$genero $especie</i> $autor";
            $nombreCactacea = "<i>$genero $especie</i> subsp. <i>$subespecie</i> $autor";


        $imagen_cactus = wp_get_attachment_image( 263, 'thumbnail' );

        echo "<tr><td><a href='#' title='$motivacion'>$nombreCactacea</a></td><td>$imagen_cactus</td></tr>";
    echo '</tbody></table></div>';

As you can see in the image, the records are loaded but the navigation bar extends so much since it is showing all the records directly.

enter image description here

when obtaining the data these are shown directly on the page but there are 268 records so my query is the way in which I could paginate all these records since I want them to be shown for example on pages of 20 records each.

, , Diego Aaron 4 years 2020-02-15T08:39:15-05:00 0 Answers 64 views 0

Leave an answer