I have a Products Page that i am using to add products using custom metaboxes this is the code for my page
<div class="container products">
<div class="row">
<?php
$count = (int)1;
$products = get_post_meta( get_the_ID(), '_cmb2_repeat_group', true );
foreach ( (array) $products as $key => $product ) {
$img = $title = $desc = '';
if ( isset( $product['product_name'] ) )
$title = esc_html( $product['product_name'] );
if ( isset( $product['product_description'] ) )
$desc = wpautop( $product['product_description'] );
$caption = wp_trim_words( $desc, 55, ' …' );
if ( isset( $product['product_image_id'] ) ) {
$img = wp_get_attachment_image( $product['product_image_id'], 'product', null, array(
'class' => 'img-thumbnail',
) );
}
if($count&1){
$span = 'col-xs-5 ' . 'col-sm-4 ' . 'col-sm-offset-1 ';
}
else{
$span = 'col-xs-5 ' . 'col-xs-offset-2 ' . 'col-sm-4 ' . 'col-sm-offset-2 ';
}
$count++;
?>
<div class="<?php echo $span; ?>box">
<a href="#">
<?php echo $img; ?>
<span class="rotate-caption hidden-xs">
<h3><?php echo $title; ?></h3>
<hr>
<p><?php echo $caption; ?></p>
</span>
</a>
</div>
<?php } ?>
</div>
</div>
i want to use pagination on this page so it displays 6 entries per page , i tried searching on wordpress pagination but i can't figure out how to use it with custom metabox , in the codex it is used with $wp_query and i can't understand how to exactly make it work in my case with custom fields. Thanks in advance
UPDATE : here is the code for the metabox itself
$meta_boxes['field_group'] = array(
'id' => 'field_group',
'title' => __( 'Manage your products here', 'cmb2' ),
'show_on' => array( 'id' => array( 11, ) ), // Specific post IDs to display this metabox
'object_types' => array( 'page', ),
'fields' => array(
array(
'id' => $prefix . 'repeat_group',
'type' => 'group',
'options' => array(
'group_title' => __( 'Product {#}', 'cmb2' ), // {#} gets replaced by row number
'add_button' => __( 'Add Another Product', 'cmb2' ),
'remove_button' => __( 'Remove Product', 'cmb2' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Product Name',
'id' => 'product_name',
'type' => 'text',
),
array(
'name' => 'Product Description',
'description' => 'Write a short description for this Product',
'id' => 'product_description',
'type' => 'textarea',
),
array(
'name' => 'Product Image',
'id' => 'product_image',
'type' => 'file',
),
),
),
),
);