WordPress.org

Forums

how to localize the number of wordpress post views? (1 post)

  1. voiceofbsl
    Member
    Posted 2 years ago #

    I want to display post view in localize number. I add these function in function.php to do so

    function make_bangla_number($str)
    {
        $engNumber = array(1,2,3,4,5,6,7,8,9,0);
        $bangNumber = array('১','২','৩','৪','৫','৬','৭','৮','৯','০');
        $converted = str_replace($engNumber, $bangNumber, $str);
    
        return $converted;
    }
    
    add_filter( 'the_views', 'make_bangla_number' );

    But I am unable to show the number in localize. Whenever i call the_views it shows the english number. Any idea how to show the post view number in localize language?

    For further info here is my post view function:

    // function to count post views.
    function setPostViews($postID) {
        $count_key = 'views';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }
    // function to display number of post views.
    function the_views($postID){
        $count_key = 'views';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0 View";
        }
        return $count.' বার';
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags