Couple of methods, depending on how much load you want to put on your server and how immediately the updates are required.
- Get all the posts, loop through them, adding a param to each post for the number of vimeo likes, then do a sort based on that.
- Store the number of vimeo likes as post meta, update this meta with cron, use
WP_Query
to sort by that meta field - Potentially - Listen for the like change from Vimeo (not sure if possible) and, on recept, update the meta value for each post, same query method as number two.
If you pick one of these that suits your project best and need example code for it, post a comment, I can write it for any of them.
edit >> code for solution 2
add_action( \'wp_insert_post\', \'my_set_vimeo_meta\' );
function my_set_vimeo_meta( $the_id, $post ) {
//$the_id contains the post id
//$post contains the post object
$vimeo_likes = ;//get your vimeo likes here, $post is your post object for any data you need
update_post_meta( $the_id, \'vimeo_likes\', $vimeo_likes );
}
//run this function in cron, either WP or linux.
function my_vimeo_cron() {
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'your_post_type\'
//any additional filtering you want to do here to only get the posts that need updating.
);
$posts = WP_Query( $args );
foreach( $posts as $k => $v ) {
$vimeo_likes = ; // get your vimeo likes again, $v is your post object for any data you need
update_post_meta( $v->ID, \'vimeo_likes\', $vimeo_likes );
}
}
you can query that with WP_Query
. It should update all your current posts as well the first time the cron runs. You probably want to tune this to your needs a good bit more, but it\'s most of the legwork done. Let me know if you need specifics on how to query the posts once they have the meta.