Support Forum
Hi
I am trying to set up a website with custom fields for measurements and have set up the fields using meta box and can see them on the post. However, I have spent hours trying to get them to show on the post and usually trigger the debug error. I am using a child theme.
This is the code in the function file of my child theme - which is working
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = 'prefix-';
$meta_boxes[] = [
'title' => esc_html__( 'Untitled', 'online-generator' ),
'id' => 'untitled',
'post_types' => ['post'],
'context' => 'normal',
'priority' => 'high',
'fields' => [
[
'type' => 'text',
'id' => $prefix . 'Neck',
'name' => esc_html__( 'Neck', 'online-generator' ),
'desc' => esc_html__( 'Width Neck', 'online-generator' ),
'placeholder' => esc_html__( 'cm', 'online-generator' ),
],
[
'type' => 'text',
'id' => $prefix . 'Shoulder',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width Shoulder', 'online-generator' ),
'name' => esc_html__( 'Shoulder', 'online-generator' ),
], [
'type' => 'text',
'id' => $prefix . 'Chest',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width chest', 'online-generator' ),
'name' => esc_html__( 'Chest', 'online-generator' ),
], [
'type' => 'text',
'id' => $prefix . 'Waist',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width waist', 'online-generator' ),
'name' => esc_html__( 'Waist', 'online-generator' ),
], [
'type' => 'text',
'id' => $prefix . 'Hem',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width hem', 'online-generator' ),
'name' => esc_html__( 'Hem', 'online-generator' ),
],
[
'type' => 'text',
'id' => $prefix . 'Length',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Length', 'online-generator' ),
'name' => esc_html__( 'Length', 'online-generator' ),
],[
'type' => 'text',
'id' => $prefix . 'Arm_Length',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Arm Length', 'online-generator' ),
'name' => esc_html__( 'Arm Length', 'online-generator' ),
],[
'type' => 'text',
'id' => $prefix . 'Hips',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width hips', 'online-generator' ),
'name' => esc_html__( 'Hips', 'online-generator' ),
],[
'type' => 'text',
'id' => $prefix . 'Thigh',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Width thigh', 'online-generator' ),
'name' => esc_html__( 'Thigh', 'online-generator' ),
],[
'type' => 'text',
'id' => $prefix . 'Rise',
'placeholder' => esc_html__( 'cm', 'online-generator' ),
'size' => 4,
'desc' => esc_html__( 'Rise', 'online-generator' ),
'name' => esc_html__( 'Rise', 'online-generator' ),
],
[
'type' => 'select_advanced',
'id' => $prefix . 'Size',
'name' => esc_html__( 'Size', 'online-generator' ),
'multiple' => true,
'options' => [
'Under size 8' => esc_html__( 'Under 8', 'online-generator' ),
'Size 8' => esc_html__( '8', 'online-generator' ),
'Size 10' => esc_html__( '10', 'online-generator' ),
'S' => esc_html__( 'Small', 'online-generator' ),
'Size 12' => esc_html__( '12', 'online-generator' ),
'Size 14' => esc_html__( '14', 'online-generator' ),
'M' => esc_html__( 'Medium', 'online-generator' ),
'Size 16' => esc_html__( '16', 'online-generator' ),
'Size 18' => esc_html__( '18', 'online-generator' ),
'L' => esc_html__( 'Large', 'online-generator' ),
'Size 20' => esc_html__( '20', 'online-generator' ),
'Over size 20' => esc_html__( 'Over 20', 'online-generator' ),
'XL' => esc_html__( 'Extra Large', 'online-generator' ),
'XXL' => esc_html__( 'XXL', 'online-generator' ),
'XXXL' => esc_html__( 'XXXL', 'online-generator' ),
],
],
],
];
return $meta_boxes;
}
This is the single.php file
<?php
/**
* The template for displaying all single posts.
*
* @package Theme Freesia
* @subpackage ShoppingCart
* @since ShoppingCart 1.0
*/
get_header();
$shoppingcart_settings = shoppingcart_get_theme_options();
$shoppingcart_display_page_single_featured_image = $shoppingcart_settings['shoppingcart_display_page_single_featured_image']; ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php global $shoppingcart_settings;
while( have_posts() ) {
the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<?php if(has_post_thumbnail() && $shoppingcart_display_page_single_featured_image == 0 ){ ?>
<div class="post-image-content">
<figure class="post-featured-image">
<?php the_post_thumbnail(); ?>
</figure>
</div><!-- end.post-image-content -->
<?php } ?>
<div class="post-all-content">
<?php $shoppingcart_entry_meta_single = $shoppingcart_settings['shoppingcart_entry_meta_single']; ?>
<header class="entry-header">
<?php
if($shoppingcart_entry_meta_single=='show'){
if ( $shoppingcart_settings['shoppingcart_post_date'] != 1){ ?>
<div class="entry-meta">
<?php printf( '<span class="posted-on"><a href="%1$s" title="%2$s"><i class="fa fa-calendar-check-o"></i>%3$s</a></span>',
esc_url(get_the_permalink()),
esc_attr( get_the_time() ),
esc_attr(get_the_time( get_option( 'date_format' ) ))
); ?>
</div>
<?php }
} ?>
<h1 class="entry-title"><?php the_title();?></h1> <!-- end.entry-title -->
<?php shoppingcart_breadcrumb();
if($shoppingcart_entry_meta_single=='show'){ ?>
<div class="entry-meta">
<?php if ( $shoppingcart_settings['shoppingcart_post_author'] != 1){ ?>
<span class="author vcard"><?php esc_html_e('Post By','shoppingcart');?><a>" title="<?php the_title_attribute(); ?>">
<?php the_author(); ?> </a></span>
<?php }
$format = get_post_format();
if ( current_theme_supports( 'post-formats', $format ) ) {
printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
sprintf( ''),
esc_url( get_post_format_link( $format ) ),
esc_attr(get_post_format_string( $format ))
);
}
if ( is_singular( 'post' ) ) {
if ( $shoppingcart_settings['shoppingcart_post_category'] != 1){ ?>
<span class="cat-links">
<?php the_category(', '); ?>
</span> <!-- end .cat-links -->
<?php }
$tag_list = get_the_tag_list( '', __( ', ', 'shoppingcart' ) );
if(!empty($tag_list)){ ?>
<span class="tag-links">
<?php echo get_the_tag_list( '', __( ', ', 'shoppingcart' ) ); ?>
</span> <!-- end .tag-links -->
<?php }
}else{ ?>
<nav id="image-navigation" class="navigation image-navigation">
<div class="nav-links">
<div class="nav-previous"><?php previous_image_link( false, __( 'Previous Image', 'shoppingcart' ) ); ?></div>
<div class="nav-next"><?php next_image_link( false, __( 'Next Image', 'shoppingcart' ) ); ?></div>
</div><!-- .nav-links -->
</nav><!-- .image-navigation -->
<?php } ?>
<?php if ( comments_open() ) {
if ( $shoppingcart_settings['shoppingcart_post_comments'] != 1){ ?>
<span class="comments"><i class="fa fa-comments-o"></i>
<?php comments_popup_link( __( 'No Comments', 'shoppingcart' ), __( '1 Comment', 'shoppingcart' ), __( '% Comments', 'shoppingcart' ), '', __( 'Comments Off', 'shoppingcart' ) ); ?> </span>
<?php }
} ?>
</div><!-- end .entry-meta -->
<?php } ?>
</header>
<!-- end .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
</div><!-- end .entry-content -->
</div> <!-- end .post-all-content -->
</article><!-- end .post -->
<?php
if ( comments_open() || get_comments_number() ) {
comments_template();
}
if ( is_singular( 'attachment' ) ) {
// Parent post navigation.
the_post_navigation( array(
'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'shoppingcart' ),
) );
} elseif ( is_singular( 'post' ) ) {
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'shoppingcart' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Next post:', 'shoppingcart' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'shoppingcart' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Previous post:', 'shoppingcart' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
}
} ?>
</div><!-- end .wrap -->
</main><!-- end #main -->
</div> <!-- #primary -->
<?php
get_sidebar();
?>
</div><!-- end .wrap -->
<?php
get_footer();
Can someone please show me what I have to put where to get it to show on the post? I would like to possibly tailor it by category later but it would be good just to get the basics working first! Sorry its probably a really basic question but nothing I try seems to work. Thanks Marie
Hi Marie,
You simply show the field's value in the loop while{...}
, just an entry meta. The code should be:
<div class="entry-meta">
<?php echo rwmb_meta( 'prefix-Neck' ) ?>
</div>
Hi Long
I've put it here in the code, but it still doesn't show anything
get_header();
$shoppingcart_settings = shoppingcart_get_theme_options();
$shoppingcart_display_page_single_featured_image = $shoppingcart_settings['shoppingcart_display_page_single_featured_image']; ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php global $shoppingcart_settings;
while( have_posts() ) {
the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<?php if(has_post_thumbnail() && $shoppingcart_display_page_single_featured_image == 0 ){ ?>
<div class="post-image-content">
<figure class="post-featured-image">
<?php the_post_thumbnail(); ?>
</figure>
</div><!-- end.post-image-content -->
<strong><div class="entry-meta">
<?php echo rwmb_meta( 'prefix-Neck' ) ?>
</div></strong>
<?php } ?>
<div class="post-all-content">
<?php $shoppingcart_entry_meta_single = $shoppingcart_settings['shoppingcart_entry_meta_single']; ?>
<header class="entry-header">
<?php
Hi,
Maybe the condition has_post_thumbnail() && $shoppingcart_display_page_single_featured_image == 0
returns false so it does not run the code.
You can try to add the code after the <article> tag, just like
<article id="post-<?php the_ID(); ?>" <?php post_class();?>>
<div class="entry-meta">
<?php echo rwmb_meta( 'prefix-Neck' ) ?>
</div>
...