• When manually updating the view counts from the edit post meta box it does not update a custom filtered meta key as described in the FAQ.

    I’ve added this filter to functions.php:

    function modify_metakey_for_bawpvc($date, $time) {
    	return $time == 'all' ? 'views' : $date;
    }
    add_filter('baw_count_views_meta_key', 'modify_metakey_for_bawpvc', 10, 2);

    To get the plugin to update the filtered meta key I’ve modified the following lines, would be great if you could update the plugin:

    Add after line 519, bawpv.php

    $meta_key = apply_filters( 'baw_count_views_meta_key', '_count-views_' . $time . $date, $time, $date );

    Replace line 521 – 524:

    if( (int)$_POST['new_views_' . $time]==0 )
    	delete_post_meta( (int)$_POST['post_ID'], '_count-views_'.$time.$date );
    else
    	update_post_meta( (int)$_POST['post_ID'], '_count-views_'.$time.$date, (int)$_POST['new_views_' . $time] );

    With:

    if( (int)$_POST['new_views_' . $time]==0 ):
    	delete_post_meta( (int)$_POST['post_ID'], '_count-views_'.$time.$date );
    else:
    	update_post_meta( (int)$_POST['post_ID'], $meta_key, (int)$_POST['new_views_' . $time] );
    	update_post_meta( (int)$_POST['post_ID'], '_count-views_'.$time.$date, (int)$_POST['new_views_' . $time] );

    With these changes it’ll update the filtered meta key, though I’ve only tested it using one filtered meta key called “views” to record the all views.

    Could you pull this into your plugin?

    Plugin version 2.19.11

    https://www.ads-software.com/extend/plugins/baw-post-views-count/

  • The topic ‘Manually updating view count with custom meta_key filter’ is closed to new replies.