Could make it work already 🙂
class MY_Post_Numbers {
private $count = 0;
private $posts = array();
public function display_count() {
$this->init(); // prevent unnecessary queries
$id = get_the_ID();
echo sprintf( '<div class="post-counter">Post number<span class="num">%s</span><span class="slash">/</span><span class="total">%s</span></div>', $this->posts[$id], $this->count );
}
private function init() {
if ( $this->count )
return;
global $wpdb;
$posts = $wpdb->get_col( "SELECT $wpdb->posts.ID
FROM $wpdb->posts
left join $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
WHERE $wpdb->posts.post_status="publish"
AND $wpdb->posts.post_type="hp_listing"
AND $wpdb->postmeta.meta_key = 'hp_rating'
ORDER BY ($wpdb->postmeta.meta_value + 0) DESC");
$this->count = count($posts);
foreach ( $posts as $key => $value ) {
$this->posts[$value] = $key + 1;
}
unset($posts);
}
}
$GLOBALS['my_post_numbers'] = new MY_Post_Numbers;
function my_post_number() {
$GLOBALS['my_post_numbers']->display_count();
}
with
<?php my_post_number(); ?>
it’s possible to use in template file if anyone else is interested