How to change the initial value of counters for view of posts

Posted in: Newspaper
Post count: 14

How can I change the initial value of counters for view of posts on a site? I want the views to start not from 0, but from 1000 views.

Thanks.

Post count: 20685

Hi,

You can do that per post, in the custom fields section of the post edit screen
http://prntscr.com/mty4wo
Change it to the value you want and update the field.

Thanks

Post count: 14

We have about 4,000 posts. We are migrating from another site. We need to massively change the number of views for all 4000 posts.

Is there any solution how to do it quickly? Plugin? Maybe make it through the database? In which file can this be found and what is the name of the field?

Post count: 14

2. By the way, in the settings of post, I do not see custom fields. Do they connect somewhere in the theme?

Post count: 1341

Make sure that you have enabled the Custom Field from Screen option from here -> https://www.screencast.com/t/qG2OoOCv and then, go to the bottom of the page, at custom fields section and make this change from there -> https://www.screencast.com/t/azFZQGE7

Post count: 32

it would be nice have the option to set a floor across the board, such as 100 on every post…

Post count: 20685

Setting a view count value for all the posts at once would be possible. For example using this function – https://pastebin.com/pKcWYFUt
The value can be changed, I set it to 1000. Enter it in the theme functions file. Refresh a post page and check if the views were updated. Then remove the function and the view should increase from the set value.

Post count: 14

Good day.

I did everything according to the instructions. But after making changes to the theme function file, the site stopped opening (error 502). Then I replaced the old function file. Now the site opens, the number of views from the records is necessary.

Questions:

1. Is it normal that the site gave an error 502?
2. Will there be consequences for such actions? Could this function make any other changes to other files or posts (of site), and as a result, errors could come out somewhere?

Thanks.

Post count: 20685

Hi,


@denisvs
I tested this again, works fine for me. That code can be entered in the functions file, at the end – http://prntscr.com/n30mul
Before the code – http://prntscr.com/n30n66
After the code – http://prntscr.com/n30ncd
Copy it as it is and paste it in the functions file at the end, shouldn’t create any problems. This code will just update the post view count for all posts, to a specified value.

The 502 error could be shown in these cases – https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-502-bad-gateway-error-in-wordpress/
Maybe it was just a coincidence.

Thanks

Post count: 14

Thank.

Do I understood correctly, in any case, there will be no negative consequences from that additional code?

Post count: 20685

Shouldn’t be any, after entering it check if the post views have been updated, then remove the code. All the post will have the view count set in the code (you can change that as you wish).

By default you can only set a custom view count by editing each post and entering the value in the custom fields section, not all of them at once. But this code should do it.

Viewing 11 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic.