Quickly Fix Your WordPress Views After Changing Themes
Introduction
Welcome to our tutorial on quickly fixing your WordPress views after changing templates! If you’ve recently switched to a new WordPress theme and noticed that your views are not displaying correctly, you’re not alone. This is a common issue that can be caused by various factors, including changes to the theme’s code or conflicts with your existing content.
Fortunately, you can take a few simple steps to resolve this issue and get your views back on track. In this tutorial, we’ll walk you through updating your views to ensure they are correctly displayed on your WordPress site.
Before we begin, it’s important to note that this tutorial assumes you have some basic knowledge of WordPress and are comfortable working with the MySQL or MariaDB database. If you’re new to WordPress, MySQL, or MariaDB or need a refresher on these topics, you may want to start with some of the other tutorials before proceeding.
Let’s get started!
Solution
You need to back up your WordPress website manually (web and database) or via the plugin. We use a plugin called UpdraftPlus. We installed and did the backup.
Next step, we access the database either via the command line or the easiest one, open up the PHPMyAdmin website and run the query from there.
When we researched what database tables we needed to modify, we came across this valuable information from WPBeaches.com on removing custom fields meta keys on the wp_postmeta table.
From here, we started playing around with the queries.
We started with this query:
select * from wp_posts;
Then we pick a blog ID as an experiment, in this case: 10631
select * from wp_postmeta
where meta_key like '%view%' AND post_id = 10631;
We found the meta_value:
zivah_post_views_count = 253 _benqu_views_count = 9
Then we figure out to join these tables:
select a.post_id, a.meta_key, a.meta_value, b.meta_key, b.meta_value
from wp_postmeta a
join (select post_id, meta_key, meta_value from wp_postmeta WHERE meta_key = "zivah_post_views_count") b
on a.post_id = b.post_id
where a.meta_key = "_benqu_views_count"
You will see that the _benqu_views_count meta_value is a lower amount than the zivah_post_views_count meta_value.
The next move is to update these.
We tested the update targetting one blog post first and picked the post_id = 10631 as an example.
UPDATE wp_postmeta a
JOIN (SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE meta_key = "zivah_post_views_count") b
ON a.post_id = b.post_id
SET a.meta_value = a.meta_value + b.meta_value
WHERE a.meta_key = "_benqu_views_count" AND
a.post_id = 10631;
Rerun the join query:
select a.post_id, a.meta_key, a.meta_value, b.meta_key, b.meta_value
from wp_postmeta a
join (select post_id, meta_key, meta_value from wp_postmeta WHERE meta_key = "zivah_post_views_count") b
on a.post_id = b.post_id
where a.meta_key = "_benqu_views_count"
and a.post_id = 10631;
You should see the meta_value changed as a sum of _benqu_views_count meta_value and zivah_post_views_count meta_value.
Run the final update query:
UPDATE wp_postmeta a
JOIN (SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE meta_key = "zivah_post_views_count") b
ON a.post_id = b.post_id
SET a.meta_value = a.meta_value + b.meta_value
WHERE a.meta_key = "_benqu_views_count";
Recheck the join query:
select a.post_id, a.meta_key, a.meta_value, b.meta_key, b.meta_value
from wp_postmeta a
join (select post_id, meta_key, meta_value from wp_postmeta WHERE meta_key = "zivah_post_views_count") b
on a.post_id = b.post_id
where a.meta_key = "_benqu_views_count";
Check the website by looking for each blog; you will see that it will reflect on the blog detail.
What next from here
We are totally in security. So once this project is completed, we disable the remote database connection on either the PHPMyAdmin website or the database firewall port and IP address.
Next, you can clean up the bloated meta post for that particular theme or template. You can follow this step-by-step from the WPBeaches.com blog.
Lastly, in our case, we use the Post Views Counter by Digital Factory side with the out-of-the-box page view as we didn’t know how to update this previously. Now, we know how to do this next time, so we disabled and deleted this plugin. We could technically run side by side, BUT then we need to figure out how to sync this view regularly. This will be the next blog post 🙂
The End
Congratulation on reaching the end of this article. We hope we have shed some light on outlining quickly you fix your WordPress views after changing themes.
We write this so that this is not a fixed article. Like in this journey, we learn as we go and re-write some parts, so please keep pinging with this article.
If you like this post, please check out our other related posts:
- Unleashing Zero Trust: Cybersecurity’s Game-Changer!
- Next-Gen Endpoint Security: Emerging Trends to Know
- Scams Exposed: Unmasking Deception & Lessons
- Healthcare Supply Chains Reimagined: Blockchain Innovations
- Get in Touch with Security Vendors: Your Guide to Contacting VirusTotal and Beyond
- Protect Your Business: Avoid These Cybersecurity Mistakes
- Scam-Proof Your Online Shopping: Tips to Identify a Legitimate Website
- Don’t Fall for the Trickery: Understanding Social Engineering and How to Protect Yourself
- How to Make Apple iPhone/iPad More Secure
- How to Install Linux and Python on iPhone or iPad
If you love this article or any programming posts and you would like to receive an update on this article or our latest post, please sign up for the form below:
Thank you.
Credits
Photo by Pixabay from Pexel