add values of variables to display on front end

I’m fairly new to both WordPress & PHP and using the add meta box function I am trying to add the values together stored in each variable to have a ‘total’ which is displayed on the front end. The user will enter the values in on the back end in their unique input field and it displays on the front end in a table format.

Here is the code used to set up the meta box:

function wpb_add_score_first_innings_meta_box() {
global $post;
if (‘142’ == $post -> ID) {
‘Live Score – First Innings’,

An example of how it is displayed on the back end:

<td><input id=”1-row-1-score” type=”text” size=”2″ value=”<?php if ( ! empty ( $live_score_first_innings_stored_meta[‘1-row-1-score’] ) ) echo esc_attr( $live_score_first_innings_stored_meta[‘1-row-1-score’][0]); ?>”></td>

An example of how it is saved to the database:

if ( isset( $_POST[‘1-row-1-score’] ) ) {
update_post_meta( $post_id, ‘1-row-1-score’, sanitize_text_field($_POST[‘1-row-1-score’] ) );

And displayed on the front end:

<td><?php $row_1_score_1 = get_post_meta($post->ID, ‘1-row-1-score’, true); echo $row_1_score_1;?></td>

For example, two variable names would be the one used in the above examples ($row_1_score_1) and another one is $row_2_score_1

Read more here:: add values of variables to display on front end

Leave a Reply

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