Skip to content

Instantly share code, notes, and snippets.

@adamcapriola
Last active January 30, 2019 18:59
Show Gist options
  • Save adamcapriola/fdb658cf83e96bf6a6803e7ef2c2f78d to your computer and use it in GitHub Desktop.
Save adamcapriola/fdb658cf83e96bf6a6803e7ef2c2f78d to your computer and use it in GitHub Desktop.
Example query for popular posts (i.e., posts with most views)
<?php
/**
* Example query: Posts ordered by most views
*
*/
$args = (
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
$posts = get_posts( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment