Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

how to auto random increment for post view

To randomly add 1-5 views, you can change the if ( $should_count block at the bottom to:

if( $should_count && ( ( isset( $views_options['use_ajax'] ) && (int) $views_options['use_ajax'] === 0 ) || ( !defined( 'WP_CACHE' ) || !WP_CACHE ) ) ) {
    $random_increment = rand( 1, 5 );
    update_post_meta( $id, 'views', $post_views + $random_increment );
    do_action( 'postviews_increment_views', $post_views + $random_increment );
}

I’m still not sure why you’d want to do this though.

Related Posts:

  1. Update Multiple Post Meta for the Same Post In One call?
  2. Updating post meta for custom post types
  3. How can I add a custom meta value on file upload?
  4. Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
  5. How can I change the meta_key for a particular piece of information?
  6. Adding custom meta boxes to specified custom post type
  7. Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
  8. Remember the Meta Value With Radio Buttons
  9. Help to Create a Simple Plugin to make a post
  10. How to securely controlling data without keeping it in postmeta?
  11. “Enable Media Replace” plugin does not update serialized object in WPMeta
  12. Performance considerations – postmeta table versus new table for custom posts with foreign keys?
  13. How to get post that has non zero or greater than zero meta value
  14. Delete postmeta when uninstall/delete plugin
  15. Storing values in Post Meta vs new tables
  16. wordpress last all added get meta value by post id
  17. Does WP identify plugin by plugin name or plugin_basename?
  18. switched from query_posts to WP_query, not working now?
  19. Making a plugin only available on the front-end for the logged in super admin
  20. Create entire wordpress as a github repositery?
  21. Help With MySQL to WPDB Query Conversion
  22. When to load auto-login code?
  23. AJAX search posts and pages
  24. How to find the origin of a file upload from within wp_handle_upload?
  25. How would I go about creating a user ranked post popularity page?
  26. CSV file generation failing
  27. What is generating my meta og:description?
  28. Updating the Drag-To-Share eXtended share URLs?
  29. finding whether request is for post, and post id
  30. Building plugin with changeable custom post type values…advice needed
  31. How to get all of the activate_plugin action parameters?
  32. __callStatic method handler passed to add_action causes bug in PHP
  33. Enqueue WordPress plugin scripts below all other JS
  34. Display update notification messages like ‘What’s New’
  35. How to add Internationalization in WordPress using Javascript/React?
  36. CRUD and Frontend show from a custom table without shortcode
  37. How to get specific setting by settings_fields()?
  38. Save / Show multi line text in metabox
  39. Creating mySQL procedure with $wpdb
  40. how to disable blockrenderAppender inside all Innerblocks?
  41. why doesn’t this update part of this plugin work? it take me to nothing here page
  42. Redirection of users away from wp-admin (but not administrators)
  43. WordPress Gutenberg react make import of __experimentalUseInnerBlocksProps which is no more experimetal
  44. Using a custom plugin to capture input data via Ajax and PHP
  45. Python with wordpress plugin
  46. Display post lists in 2nd paragraph
  47. Map Custom Registration Fields to WordPress User Roles
  48. Not able to add option in Sub-Menu under page
  49. How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
  50. Using a post-signup hook to get user details
  51. Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
  52. How to apply a patch via plugin?
  53. Fixing WordPress’s Bug (failed to send buffer of zlib output compression) results in “White Screen of Death”
  54. Disable woocommerce cookies and delete cart data automatically
  55. Ajax contact form widget plugin data not insert in database
  56. How to display the “ratingValue” and “ratingCount” values ​generated by the KK Star Ratings plugin into my page’s recipe ld+json schema
  57. link bbpress forum discussion to blogposts
  58. Install Plugin via Code
  59. code is working properly in Core PHP but writing coding in WordPress
  60. Combine scripts from all extensions of the plugin when an extension is activated
  61. Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
  62. Prevent duplicate records in plugin table
  63. Send Custom welcome email to specific user group
  64. woocommerce payment gateway callback not firing [closed]
  65. How to modify WCMP Rest API response?
  66. Fetch Children of Grouped Products Inside WooCommerce Product Loop
  67. White page by using filter template_include
  68. How to fetch products with the price in a page on woocommerce using a form or live search with php
  69. Making a Template for a CPT created by a plugin
  70. Woocommerce dependent plugin
  71. WordPress.org Plugin Directory doesn’t recognise screenshots [closed]
  72. External CSS in WordPress Plugin [closed]
  73. How to check current user before all actions and filters?
  74. Owl Carousel2 image not displaying full width when using Stretch row and content, Stretch row and content(no padding) in wordpress
  75. User Session and Stored Cookies not get removed
  76. New databes tables with – WooCommerce – for developers [closed]
  77. How can I prevent my plugin go development trunk [closed]
  78. Plugin-generated pages use Not Found or Pages Archive templates?
  79. How can I make 2 plugins that include different versions of a framework to both use the latest version?
  80. creating html reusable blocks via shortcodes
  81. Add Plugin options as subpage to Theme options page
  82. Is there any kind of theme on WordPress to sell my own movies?
  83. Image upload and download from front-end
  84. get current date + 90 days and checking every day
  85. Create a navbar filter that filters by a custom field
  86. Change commission_status paid when withdraw_status vendor is completed
  87. Passing an array from shortcode-function to filter-function
  88. custom payment gateway in woocommerce failed to connect to remote api server
  89. wp_remote_get() returns 403 while file_get_contents() does not
  90. Single API call exposed via shortcode with params
  91. Plugin options page with live preview?
  92. Using SVN to upload plugin created with gutenberg blocks
  93. Force quit running background job
  94. Modifying Author Link to add Author Meta in URL
  95. How to output CMB2 select options from repeated groups select elements?
  96. Creating a Callback URL for WordPress Woocommerce to update Order Status
  97. Get Time Taken By Each Action Hook in WordPress
  98. How to export post 2 posts WordPress plugin data [closed]
  99. 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
  100. WordPress plugin creation how to execute .sql in order to insert multiple rows at activation of plugin
Categories plugins Tags plugin-development, plugins, post-meta
when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
Override category archive page title (not the head title)

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress