1

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";
        else: 
            $nombreCactacea = "<i>$genero $especie</i> subsp. <i>$subespecie</i> $autor";

        endif;

        $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.

1 Answer 1

-1

You can use wordpress query args options. I hope this will help you.

// WP_Query arguments
   $args = array (
     'nopaging'               => false,
     'posts_per_page'         => '5',
);
// The Query
$query = new WP_Query( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.