Skip to content

Instantly share code, notes, and snippets.

@jorgepedret
Created July 8, 2011 01:13
Show Gist options
  • Save jorgepedret/1070901 to your computer and use it in GitHub Desktop.
Save jorgepedret/1070901 to your computer and use it in GitHub Desktop.
quick wp stuff
<?php
funcion get_years(){
$results = $wpdb->query("SELECT DISTINCT YEAR(meta_value) as year FROM wp_postmeta WHERE meta_key = 'release_date'");
echo '<select>';
foreach($results as $result){
echo '<option>'.$result->year.'</option>';
}
echo '</select>';
}
function get_posts_by_year($year){
$query = "SELECT post_id FROM wp_postmeta WHERE meta_key = 'release_date' AND YEAR(meta_value) = '".$year."'";
$results = $wpdb-query($query);
foreach($results as $result){
$post = get_post($result->post_id);
echo $post->post_title;
}
}
get_posts_by_year($_GET['year']);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment