Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How can I output WPAlchemy repeating fields meta values in my page template?

Per comments, here’s a (very rough) example of accessing repeated fields in the frontend. Note using WPAlchemy extract mode, which gives each field its own meta entry, and makes accessing them a bit simpler.

Also using actions in “functions.php” to add metabox and to output content for test purposes – obviously you’d adapt the 'init' code to your custom post type and put the 'the_content' code in your page template.

Eg, in “functions.php”:

define( 'METABOX_ID', 'my_meta_' );
add_action( 'init', function () {
    if ( is_admin() ) {
        if ( ! class_exists( 'WPAlchemy_MetaBox' ) ) {
            require_once 'wpalchemy/MetaBox.php'; // Assuming subdirectory of current theme directory.
            require_once 'wpalchemy/MediaAccess.php'; // Assuming subdirectory of current theme directory.
        }
        global $wpalchemy_media_access;
        $wpalchemy_media_access = new WPAlchemy_MediaAccess();
        $download_meta = new WPAlchemy_MetaBox(
            array(
                'id' => METABOX_ID,
                'types' => array( 'post' ), // array( 'downloads' )
                'template' => get_stylesheet_directory() . '/download_meta.php',
                'priority' => 'default',
                'mode' => WPALCHEMY_MODE_EXTRACT,
                'prefix' => METABOX_ID,
            )
        );
    }
} );

// Just for testing - should be in the custom post type template.
add_action( 'the_content', function ( $content ) {
    if ( is_single() ) {
        $post_id = get_the_ID();
        // Access single-valued (non-array) meta.
        $ul_class="docs";
        if ( $cb_second_includes = get_post_meta( $post_id, METABOX_ID . 'cb_second_includes', true ) ) {
            $ul_class="docs_second_includes";
        }
        // Access array-valued meta.
        if ( $docs = get_post_meta( $post_id, METABOX_ID . 'docs', true ) ) {
            ob_start();
            ?>
            <ul class="<?php echo $ul_class; ?>">
            <?php foreach ( $docs as $doc ) : ?>
                <li><?php echo $doc['li-text']; ?></li>
            <?php endforeach; ?>
            </ul>
            <?php
            $content = $content . ob_get_clean();
        }
    }
    return $content;
} );

Here’s the version of “download_meta.php” I used (note the metabox is addressed via $mb):

<?php global $wpalchemy_media_access; ?>
<div class="my_meta_control">
  <label>Includes:</label>
  <?php $mb->the_field('cb_second_includes'); ?>
  <p><input type="checkbox" class="second-includes-check" name="<?php $mb->the_name(); ?>" value="1"<?php $mb->the_checkbox_state('1'); ?>/><span>Different bullet points for previous version?</span></p>
  <div class="clearfix">
    <?php while($mb->have_fields_and_multi('docs')): ?>
    <?php $mb->the_group_open(); ?>
      <?php $mb->the_field('li-text'); ?>
      <?php $wpalchemy_media_access->setGroupName('li-n'. $mb->get_the_index())->setInsertButtonLabel('Insert'); ?>
      <div class="col includes">
        <?php echo $wpalchemy_media_access->getField(array('name' => $mb->get_the_name(), 'value' => $mb->get_the_value())); ?>
        <a href="#" class="dodelete button" style="float:right;">-</a>
      </div>
    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>
  </div>
  <p style="margin-bottom:0; padding-top:0;"><a href="#" class="docopy-docs button">+</a></p>
</div>

Related Posts:

  1. Detect meta value changes when post is updated (post_updated)
  2. Displaying Meta Box Image
  3. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  4. Populate Custom Fields in a Custom Post Type?
  5. How to check if user meta field is empty in conditional else statement
  6. A better way to add a meta box to custom post types
  7. create custom meta box with default value
  8. Add a class to post_class if more than one post shares same meta_value_num
  9. Add a meta field to the list of results for a custom post type
  10. Empty meta-box returns publishdate if no value is set?
  11. Custom Post Type meta data getting deleted on bulk editing taxonomies
  12. Delete custom post type metadata without deleting the post in admin area
  13. Plugin – Combine Meta Box Input Fields into single saveble record
  14. Two Custom Post Types Many to Many Relationship
  15. get_post_meta not working on publishing
  16. Meta Query Filtering not working on Custom Meta Box using Radio Buttons
  17. How do I set all of a particular post meta to a value within the custom post type I’m in?
  18. Grouping metadatas into one
  19. Metabox not show in categories custom post type cmb2
  20. Repeatable Fields Metabox with Textarea (or wp_editor)
  21. How to use TinyMCE Editor for one of my custom post meta field?
  22. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  23. Show Custom Post Type meta boxes only on Page Edit
  24. Cannot save CPT meta box
  25. Adding Page Templates to post but it ignored it
  26. get_posts in meta box dropdown not showing latest posts
  27. Importing Data from a Non-WordPress database, into WP
  28. Permalinks: custom structure for taxonomy – tags?
  29. Can’t publish custom post type – “You are not allowed to edit this post.”
  30. Custom fields for custom post type
  31. Custom “radio button meta box” not saving correctly
  32. Meta Data for Custom Post Type not saving
  33. Add additional field to custom post_type
  34. Custom Post Meta from custom metaboxes is randomly being deleted
  35. Check if post with same meta value exists
  36. Add a custom meta box for client to order CPT posts how they want
  37. Submitting Custom Post Types with custom fields from Front-end form
  38. Display Repeatable Meta Box Content
  39. Displaying a div from an assigned meta_value when on a page
  40. How to Echo Metadata Value in Currency Format
  41. Issue on Working with Metabox – Checkbox to enable Sale Items
  42. delete_post_meta() for whole CPT / multiple posts?
  43. How to get specific post meta by title or id
  44. What do the numbers mean at the end of add_action(‘save_post’)…?
  45. A meta box (in a custom post type) with two different type of fields
  46. Why do I have to press the “Update” button twice to save my meta box values?
  47. Values from meta-box not on $_POST
  48. Custom post type suddenly stoped working after WordPress 5 update
  49. copy images from custom field to another custom field
  50. How to show custom field on specific custom post type posts only when filled
  51. Reusable metabox backend and frontend
  52. Cannot obtain custom meta information
  53. Get custom term meta problem on single post type
  54. Display custom meta on page that has been check in custom post type
  55. Meta box data is saved but NOT displayed in the meta box text field. Why?
  56. How to call a post’s metadata in shortcode.php?
  57. How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
  58. Save Metabox Custom Field Value
  59. Meta box data not saving
  60. WP_Meta_Query object with conditionals
  61. Related posts meta_query CPT
  62. Meta box with front-end styling
  63. Sanitaizing Select Optin For Custom Post Type Metabox in WP
  64. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  65. Cannot Save MetaBox Data in Custom Post Type
  66. Adding an extra parameter [string] to my posts’ permalink?
  67. delete duplicate meta_value with same post_id
  68. Search CPT Title AND Meta
  69. updating one custom meta field only
  70. Problem On Retrieving Post Meta Data on Custom Column [closed]
  71. Function to return values from metabox
  72. Saving metabox keys and storing values as array
  73. Custom Post Type Meta Box Text Input Field Won’t Save When Blank
  74. Filter search posts by post meta?
  75. Custom Meta Box with variable number of fields
  76. Custom fields for post or terms which don’t update on post update
  77. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  78. How to keep custom post type related information
  79. How to avoid duplicate posts queried from custom meta?
  80. Custom Metabox Info Not Saving
  81. How can I add a meta[] to my custom post type and search by term with the Rest API?
  82. Show posts from WP Custom Post Type selected from a field in a metabox
  83. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  84. Where is get_post_meta value located?
  85. PHP Warning with Custom Fields
  86. Custom meta fields not showing up in WP_Response Object via custom endpoint
  87. Problem with multi checkboxes value in metabox?
  88. Get meta values from parent post and save in child post
  89. How to Disable option of meta field if that option is selected for any other post in custom post type?
  90. Simple Data picker meta box
  91. Metaboxes in Loop
  92. Add more custom fields when creating a new custom post type
  93. check_admin_referer not working in custom meta box for custom post type
  94. Custom meta box data not saving
  95. How do I extract the contents of a CPT’s custom field for all posts?
  96. Collect custom post in a calendar
  97. Avoid another meta box in my custom post type
  98. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  99. How to add post reference field to a plugin?
  100. Search form to find custom meta box generated data
Categories custom-post-types Tags custom-field, custom-post-types, metabox, post-meta, wpalchemy
Get usermeta info from sql query
Custom post type and taxonomy cross registration [duplicate]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress