I am performing the below code within wordpress. To give a brief outline of what I am trying to achieve: I query the database to return a list of exercises, values (reps and sets for exercises) are assigned to them and stored in $_SESSION in the following array structure.
Array
(
[0] => Array
(
[ExerciseID] => 75
[Sets] =>
[Reps] =>
)
[1] => Array
(
[ExerciseID] => 690
[Sets] => 3
[Reps] => 3
)
)
The code: I return the exercise ID's into a array so I can then run a WP_Query using them. When the results are returned I need them to display the reps and sets (the variables that are in the array) with the exercise.
<?php
$ids = array();
if(empty($_SESSION['collection']))
{echo"<p>There's nothing in your collection, an add some by searching above</p>";}
else
{
foreach($_SESSION['collection'] as $el)
{
$ids[] = $el['ExerciseID'];
}
}
// START OF THE QUERY USING THE EXERCISE ID'S FOR DISPLAYING IN THE COLLECTION
$the_query = new WP_Query(array('post__in' => $ids, 'post_type' => 'exercise', 'posts_per_page' =>'100')); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="thumbnail">
<div class="caption" id="<?php the_ID(); ?>">
<h5>
<?php the_title(); ?>
</h5>
<?php the_post_thumbnail('collection_thumb'); ?>
</div>
<br />
<form action="" method="post">
<button class="btn btn-primary btn-m" type="submit" name="delete" value="Delete">Delete</button>
</form>
</div>
I am struggling matching the reps and sets to be displayed along side the exercise that has been queried.
Apologies for the poor explanation, by clicking on a exercise on this website and adding it to the collection hopefully you can see what I am trying to achieve.