Support » Plugin: Jetpack Post Views » Don't display 'jetpack-post-views' for scheduled post

  • Resolved sima313


    Hi Steven!

    I have the following problem on my website.
    I have a miltiauthor website and we recieve a lot of posts from our authors. Our editor uses the sheduled post function becouse it saves time for us.

    Unfortunately when we started using sheduled post function I found out that published posts do not disply unlimited jetpack statistic. I use the following function:

    get_post_meta( $post->ID, ‘jetpack-post-views’, true );

    Although when I publush posts manually everything is fine.

    I try to solve this problem by manually updating already published post. Only then the post count shows up.

    I looked into database and saw that in the postmeta table after scheduled publishing of the post the ‘jetpack-post-views’ item is not created. Althought there are ‘jetpack-post-views-(daily,monthly,yearly)’ items.

    Also when I preview any post which have not been published yet, I do not see post count.

    I think this happens because the function that creates item in the postmeta database table is triggered only when the post in published manualy.

    Could you please investigate this issue and advice how I can modify the code to trigger database updating function for scheduled posts published.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Steven Lambert


    In my code I have a hook set on when the publish post button is activated that just adds the option to the post id and sets it to 0. I’m not sure how schedule posts operate, but I assume they have a similar hook that you could set the same thing for.

    Here is the code for your reference:

    add_action( 'publish_post', array( &$this, 'add_jetpack_meta' ) );
    function add_jetpack_meta() {
    global $post;
    add_post_meta( $post->ID, 'jetpack-post-views', 0, true );

    I found that for scheduled posts there is ‘publish_future_post’ add_action parameter, which triggers when the post is published.
    Unfortunately when I first time added…

    add_action( ‘publish_future_post’, array( &$this, ‘add_jetpack_meta’ ) );

    …it does not work.

    I found info about how wp cron operates with post ID here

    I used instead of “global $post;” -> “$post_id” and it worked!

    Just to conclude. Finally I added the following code:

    // Future Post publish hooks
    add_action( ‘publish_future_post’, array( &$this, ‘add_jetpack_meta_future’ ) );

    function add_jetpack_meta_future( $post_id ) {
    add_post_meta( $post_id, ‘jetpack-post-views’, 0, true );

    Thank you Steven for your assistance! This topic is resolved now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Don't display 'jetpack-post-views' for scheduled post’ is closed to new replies.