get_var( $wpdb->prepare( " SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'hits' LIMIT 1 ", $post_id ) ); /////////////////////////////////////////////////////////////////////////////// if( empty($current_hits) ) { $current_hits = 1; // insert new $wpdb->query( $wpdb->prepare( " INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, 'hits', %d ) ", $post_id, $current_hits ) ); } else { $current_hits++; // update_post_meta $wpdb->query( $wpdb->prepare( " UPDATE $wpdb->postmeta SET meta_value = %d WHERE post_id = %d AND meta_key = 'hits' ", $current_hits, $post_id ) ); } /////////////////////////////////////////////////////////////////////////////// die( strval( $current_hits ) ); ///////////////////////////////////////////////////////////////////////////////