You can automatically add a custom field to each new post on publish (on change status to publish). And then set it’s value to a random number between 829 and 1013.
Here is the function that will do just that.
// Create custom field on post publish
function wpse_custom_field_on_publish( $new, $old, $post ) {
if ( $new == 'publish' && $old != 'publish' && !get_post_meta( $post->ID, 'post_views', true ) ) {
add_post_meta( $post->ID, 'post_views', rand(829, 1013), true );
}
}
add_action( 'transition_post_status', 'wpse_custom_field_on_publish', 10, 3 );
In above code, post_views
is the name of the custom field that we are using to count post views. You should change it to yours before using it in your theme.
Just FYI, this will go in functions.php
file.
Related Posts:
- Hide the post count behind Post Views (Remove All, Published and Trashed) in Custom Post Type
- Get total views of all posts by author
- C++ – how to find the length of an integer
- How can I make a PHP counter?
- Counting the posts of a loop (WP_Query)?
- Category and children post count
- How to display 2 equal columns of li based on the count of items in wp_nav_menu divided by 2?
- Show weekly posts statistic in WordPress
- Count number of posts by author in a category
- How we count the user draft posts
- Double count view in archive.php
- What is the best way to count and display the number of posts?
- How can I count post views of REST API calls and update them in an ACF field?
- Get count of terms with a post and another taxonomy term?
- How can I get global $post to work for CPT and update user?
- Get Gravity Forms field values and count how many? [closed]
- Counting posts in custom post type by author
- Show ellipsis (…) only if the number of characters exceeds limit defined in substr
- Post Views / Hit Counter Problem?
- Count post views in loop
- Count post + add number =
- How to do simple addition to increase favorites count of my wordpress posts
- Count posts published in one particular day: the lighter way
- What is the best way to do this? [closed]
- Search Count WordPress Theme
- How to read out the excerpt length (for if-condition)
- $count_posts->draft & published
- Count the total views of all user posts published
- Author.php Page views counter
- CountPost WordPress Custom Taxonomy
- get the count of table rows
- How to calculate posts number? [closed]
- How make animation increase of number
- Having problems getting the number of plays in a WordPress Playlist from an audio file
- How to show the amount of post that have on the site?
- Adding a posts count in archive pages
- Adding count also to parent categories
- Counting the number of elements with the values of x in a vector
- PHP 7.2 – Warning: count(): Parameter must be an array or an object that implements Countable
- How can I count the occurrences of a list item?
- How to count the occurrence of certain item in an ndarray?
- Pandas ‘count(distinct)’ equivalent
- Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy
- Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy
- How to sort a list of objects based on an attribute of the objects?
- Count the number of occurrences of a character in a string
- Calculate average in java
- Counting the occurrences / frequency of array elements
- Count how many files in directory PHP
- What is the difference between a stored procedure and a view?
- How to count the number of files in a directory using Python
- How to find length of digits in an integer?
- select * from table where column = something or, when unavailable, column = something else
- select count(*) from table of mysql in php
- How to get the count of each distinct value in a column?
- How to count instances of character in SQL Column
- How to mark every 3rd post
- Return only Count from a wp_query request?
- Count & Display Database Queries
- Count posts within a custom post type and specific taxonomy and terms?
- How to Display a List of Users Who Have Made at Least 1 Post?
- How to Display Network Post Count?
- Taxonomy count per Post type
- WP 3.5 and Galleries – how to count images?
- Count the number of images uploded on the website
- Total word count for posts by one author
- How to cache a shortcode functions output?
- show number of open comments on custom dashboard
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- count posts from custom taxonomy terms by year
- Count posts or custom post types from last 24 hours (or from today)
- Comment Count for each Comment Author
- Display user’s total comment count outside The Loop
- Custom Post Type With Different Views
- Creating a custom MCE view for your shortcodes [closed]
- Count posts that have specific taxonomy term attached
- Count post that have specific meta value
- Count posts in category including child categories
- WP Admin default view mode for Custom Post Type
- How to count current user’s pages?
- Audio or playlist shortcode condition according to the amount of files on attachment page
- Count user posts by type and date
- Writing a view count with w3 total cache
- How to update incorrect post count in taxonomy?
- Popular posts by view with Jetpack
- Count singular post views automatically
- taxonomy list display custom post count
- Count number of post in Taxonomy?
- Display the number of published posts for each custom taxonomy term?
- Add link on the top menu of the post table?
- Set font size automatically according to number of words in post
- Display posts from Last 24 hours and order them based on most views
- Count custom post types with a specific meta value
- User Published Post Count
- Custom Post Type Category List & Post Count
- Limit tag word count
- Problem with get_posts, tax_query and counting the number of posts
- Network wide post count (WP Multisite)
- How to use global post counter in the loop?
- Add character count to custom metabox