Last active
December 24, 2015 01:59
-
-
Save hchouhan/6727356 to your computer and use it in GitHub Desktop.
IRT raw Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dot_most_recommended_posts($numberOf, $before, $after, $show_count, $post_type="showcase" ) { | |
global $wpdb; | |
$request = "SELECT * FROM $wpdb->posts, $wpdb->postmeta"; | |
$request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id"; | |
$request .= " AND post_status='publish' AND post_type='$post_type' AND meta_key='_recommended'"; | |
$request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $numberOf"; | |
$posts = $wpdb->get_results($request); | |
foreach ($posts as $item) { | |
$post_title = stripslashes($item->post_title); | |
$permalink = get_permalink($item->ID); | |
$post_count = $item->meta_value; | |
echo $before.'<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . $post_title . '</a>'; | |
echo $show_count == '1' ? ' ('.$post_count.')' : ''; | |
echo $after; | |
} | |
} | |
$options = get_option("dot_most_recommended_posts"); | |
if (!is_array( $options )) | |
{ | |
$options = array( | |
'title' => 'Most recommended posts', | |
'number' => '10', | |
'show_count' => '1', | |
); | |
} | |
$title = $options['title']; | |
$numberOf = $options['number']; | |
$show_count = $options['show_count']; | |
echo '<ul class="mostrecommendedposts">'; | |
dot_most_recommended_posts($numberOf, '<li>', '</li>', $show_count); | |
echo '</ul>'; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment