• Resolved pervect

    (@pervect)


    By default the views count is rendered below the player.
    The idea is to render it at the other place of the page.

    So, the question is:
    1) what code should I use at my template to render this string or
    2) what variable (like e.g. `$meta = wp_read_video_metadata($path);
    echo $meta[‘length_formatted’];` for the video duration) should I use?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Kyle Gilman

    (@kylegilman)

    The plugin stores a lot of information in _kgvid-meta. View counts are in the index starts. I would display it using code like this (which I have not tested) where $video_id is the post ID of the video.

    $kgvid_postmeta = get_post_meta($video_id, "_kgvid-meta", true);
    
    if ( !empty($kgvid_postmeta) 
    	&& is_array($kgvid_postmeta) 
    	&& array_key_exists('starts', $kgvid_postmeta) 
    ) {
    	echo $kgvid_postmeta['starts'];
    }
    Thread Starter pervect

    (@pervect)

    It did not work:

    Undefined variable: video_id

    Plugin Author Kyle Gilman

    (@kylegilman)

    As I said, $video_id is the post ID of the video. I don’t know how your template is set up, so I don’t know what variable your video’s post ID is stored in. I used $video_id as an example.

    get same problem

    when i tryin

     $postmeta = get_post_meta(get_the_ID());
      var_dump( $postmeta );

    i get only

    array(6) { ["inline_featured_image"]=> array(1) { [0]=> string(1) "0" } ["_edit_lock"]=> array(1) { [0]=> string(12) "1499598881:2" } ["_thumbnail_id"]=> array(1) { [0]=> string(3) "545" } ["_edit_last"]=> array(1) { [0]=> string(1) "2" } ["_encloseme"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" } ["_kgvid_first_embedded_video"]=> array(1) { [0]=> string(124) "a:2:{s:4:"atts";s:0:"";s:7:"content";s:78:"https://twinkspire.com/elefant/wp-content/uploads/showing-it-off-TwinkSpire.mp4";}" } }

    array key _kgvid-meta is not present

    Plugin Author Kyle Gilman

    (@kylegilman)

    get_post_meta without a second argument gets the built-in WordPress post meta. In your case you could use this to get the plugin’s custom meta.

    $kgvid_postmeta = get_post_meta(get_the_ID(), "_kgvid-meta", true);

    following code

    $kgvid_postmeta = kgvid_get_attachment_meta( get_the_ID() );

    returns default array, as i see from source of plugin

    array(41) { ["embed"]=> string(12) "Single Video" ["width"]=> string(0) "" ["height"]=> string(0) "" ["actualwidth"]=> string(0) "" ["actualheight"]=> string(0) "" ["downloadlink"]=> bool(false) ["track"]=> string(0) "" ["starts"]=> string(1) "0" ["play_25"]=> string(1) "0" ["play_50"]=> string(1) "0" ["play_75"]=> string(1) "0" ["completeviews"]=> string(1) "0" ["pickedformat"]=> string(0) "" ["encodefullres"]=> string(0) "" ["encode1080"]=> string(0) "" ["encode720"]=> string(0) "" ["encodemobile"]=> string(0) "" ["encodewebm"]=> string(0) "" ["encodeogg"]=> string(0) "" ["encodecustom_h264"]=> string(0) "" ["encodecustom_webm"]=> string(0) "" ["encodecustom_ogg"]=> string(0) "" ["encodecustom"]=> string(0) "" ["rotate"]=> string(0) "" ["autothumb-error"]=> string(0) "" ["numberofthumbs"]=> string(2) "10" ["randomize"]=> string(0) "" ["forcefirst"]=> string(0) "" ["featured"]=> string(2) "on" ["thumbtime"]=> string(0) "" ["lockaspect"]=> string(2) "on" ["showtitle"]=> string(0) "" ["gallery_thumb_width"]=> string(3) "250" ["gallery_exclude"]=> string(0) "" ["gallery_include"]=> string(0) "" ["gallery_orderby"]=> string(0) "" ["gallery_order"]=> string(0) "" ["gallery_id"]=> string(0) "" ["duration"]=> string(0) "" ["aspect"]=> string(0) "" ["original_replaced"]=> string(0) "" }

    Plugin Author Kyle Gilman

    (@kylegilman)

    Sorry, I misread this. Using get_the_ID() is the problem. That gets post meta for the post, not the video. You need to get the post ID of the video first.

    this code $kgvid_postmeta = get_post_meta(get_the_ID(), "_kgvid-meta", true);

    returns string(0);

    thanks, teh next snippet helpled me

    
    $video = get_attached_media('video', get_the_ID() );
    $first = array_shift($video);
    $kgvid_postmeta = get_post_meta($first->ID , "_kgvid-meta", true);
              
    
                if ( !empty($kgvid_postmeta) 
                	&& is_array($kgvid_postmeta) 
                	&& array_key_exists('starts', $kgvid_postmeta) 
                ) {
                	echo 'Views: '.$kgvid_postmeta['starts'];
                }
    

    not post id of video, but attached media id ))

    Plugin Author Kyle Gilman

    (@kylegilman)

    Looks good to me!

    Sorry if I was unnecessarily confusing. Media attachments are “posts” in the WordPress database so what you’re doing is actually getting the post ID of the video, but most people don’t refer to them that way.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to get the view count?’ is closed to new replies.