Support

Account

Home Forums Pre-purchase Questions Post Views Counter

Solving

Post Views Counter

  • Hi,

    is it possible to create a custom field for page views?
    Everytime when a post is loaded the view counter should increase and will be saved in the custom field.

    best regards,
    Sascha

  • In the template file, get the field, increment it and then save it

    
    $count = get_field('counter_field);
    $count++;
    update_field('counter_field');
    
  • Thanks John, but your code didn’t work for me..

    Managed to find something that did work, thought I’d add it here in case anyone else comes looking..

    
    // Get the current value.
    $count = (int) get_field('counter_field');
    // Increase it.
    $count++;
    // Update with new value.
    update_field('counter_field', $count);
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.