Skip to content

Instantly share code, notes, and snippets.

@hchouhan
Last active December 9, 2022 18:49
Show Gist options
  • Save hchouhan/4be601dcefe40d9bdbc9 to your computer and use it in GitHub Desktop.
Save hchouhan/4be601dcefe40d9bdbc9 to your computer and use it in GitHub Desktop.
IRT Shortcode
add_shortcode( 'dot_recommended_posts', array( &$this, 'dot_recommended_top_posts' ) );
function dot_recommended_top_posts( $atts, $content = null )
{
// define attributes and their defaults
extract( shortcode_atts( array (
'container' => 'li',
'number' => '10',
'post_type' => 'post',
'year' => '',
'monthnum' => '',
'show_count' => '1',
), $atts ) );
global $wpdb;
$request = "SELECT * FROM $wpdb->posts, $wpdb->postmeta";
$request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
if ($year != '') {
$request .= " AND YEAR(post_date) = '$year'";
}
if ($monthnum != '') {
$request .= " AND MONTH(post_date) = '$monthnum'";
}
$request .= " AND post_status='publish' AND post_type='$post_type' AND meta_key='_recommended'";
$request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $number";
$posts = $wpdb->get_results($request);
$return = '';
foreach ($posts as $item) {
$post_title = stripslashes($item->post_title);
$permalink = get_permalink($item->ID);
$post_count = $item->meta_value;
$return .= '<' . $container . '>';
$return .= '<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . $post_title . '</a> ';
if ( $show_count == '1') {
$return .= '<span class="votes">' . $post_count . '</span> ';
}
//$return .= get_the_post_thumbnail($item->ID, 'showcase-thumbnail');
$return .= '</' . $container . '>';
}
return $return;
} //dot_recommended_top_posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment