Foreach with pagination

I would like to create a pagination, but it is a foreach instead of a wp_query loop.

global $wpdb;

$table_name = ‘esma_member’;

$search = ”;
$general = “SELECT member_id,img_logo,company_type, company_name, company_description FROM esma_member “;

$allmembers = $wpdb->get_results( );

if(isset($_GET[“search_member”])){
$search = $_GET[“search_member”];
$query = ” WHERE company_name LIKE ‘%$search%’ OR company_type LIKE ‘%$search%’ OR country LIKE ‘%$search%’;”;

if($search!=”){
$sql = $general.$query;
}else{
$sql = $general;
}
$query_result = $wpdb->get_results($sql) or die(mysql_error());

foreach ( $query_result as $m ) {
$result[] = $m;
}

} else{
$sql = $general;
$query_result = $wpdb->get_results($general) or die(mysql_error());

foreach ( $query_result as $m ) {
$result[] = $m;
}

}

<?php foreach ($result as $v) { ?>
<section class=”libary”>
<a href=”/profile-page/?member_id=<?php echo $v->member_id; ?>”>
<div class=”logowrap”>
<?php echo wp_get_attachment_image( $v->img_logo, array(‘700’, ‘600’), “”, array( “class” => “img-responsive” ) ); ?>
</div>
<div class=”member_inner”>
<p><?php echo $v->company_type; ?></p>
<h3><?php echo $v->company_name; ?></h3>
<p><?php echo $v->company_description; ?></p>
</div>
</a>
</section>
<?php } ?>

It must to be a number pagination. As you can see the information comes from a table.

Thank you

Read more here:: Foreach with pagination

Leave a Reply

Your email address will not be published. Required fields are marked *