This is a bit beyond my skill level. In WordPress I want to output some data from multiple pages. I have a query set up to do this no problem. However, as the query loops through each page, I am adding in some extra data, a points system. Is there a way that I can load all of this data into an array (instead of printing it directly), then sort the array by points, then print the array?
Here is my code so far. At the moment it is just printing the needed data, not sorting anything.
<ol>
<?php $this_page_id=$wp_query->post->ID; ?>
<?php query_posts(array('post_parent' => $this_page_id, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
<li><?php
the_post_thumbnail();
the_title();
/* Calculate Points. YouTube views multiplied by likes. Relevant video ID is stored in post meta. */
$video_ID = get_post_meta( get_the_ID(), 'sweetworld_video', true );
$JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'};
$likes = $JSON_Data->{'entry'}->{'yt$rating'}->{'numLikes'};
$points = $views * $likes;
echo $points;
?></li>
<?php } ?>
</ol>
Question
jordan.
Hi guys,
This is a bit beyond my skill level. In WordPress I want to output some data from multiple pages. I have a query set up to do this no problem. However, as the query loops through each page, I am adding in some extra data, a points system. Is there a way that I can load all of this data into an array (instead of printing it directly), then sort the array by points, then print the array?
Here is my code so far. At the moment it is just printing the needed data, not sorting anything.
Help is greatly appreciated.
Thanks,
Jordan
Link to comment
Share on other sites
2 answers to this question
Recommended Posts