I am trying to add the values of a variable together and display the total value.
I am using posts to posts to create a connection between my custom post types 'recipes' and 'ingredients'. the ingredients post type has a custom meta field with the key 'foxware-ingredient-cost'. As you can see in the code below i assign the value from the meta key to the variable $cost. Then i am trying to add each of those values together, but the code i have doesn't seem to do anything except return the first value, the plus sign seems to have no effect here. Do i need to put the values of $cost variable into an array or something?
<?php $connected = new WP_Query( array( 'connected_type' => 'recipes_to_ingredients', 'connected_items' => get_queried_object(), ) ); while( $connected->have_posts() ) : $connected->the_post(); $cost = get_post_meta( $post->ID, 'foxware-ingredient-cost', true ); echo '<li>'; the_title(); // Display cost echo '<br>'; echo 'Cost: ' . $cost; echo '</li>'; endwhile; echo ($cost + $cost); ?>