3

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, ' &hellip;' );


            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',
                ),
            ),
        ),
    ),
);
12
  • Just so it's clear, you are trying to paginate custom field values on a single post, displaying 6 values per page?
    – jdm2112
    Commented Nov 3, 2014 at 15:21
  • Where is these metaboxes? Commented Nov 3, 2014 at 15:22
  • @PieterGoosen edited the post ive added the metabox code, i just want to ensure you that it is displayed on the frontend just fine my issue how is how to add pagination support to this Commented Nov 3, 2014 at 15:37
  • @jdm2112 thanks for following on , as you can see it is a group field i have created using github.com/WebDevStudios/… , so once the client wants to add new product he will have 3 fields to complete image , name and description .. like you have said i want the pagination to display 6 entries per page Commented Nov 3, 2014 at 15:40
  • 1
    i am already on the track for restructure , thanks everyone for your help , great community! Commented Nov 3, 2014 at 16:15

0

Your Answer

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

Browse other questions tagged or ask your own question.