My first CGI program was The Lucas Problem puzzle. I showed it to everyone who was connected to the Internet.
Along Comes WordPress
I wanted an interactive blog. I tried Pebble before WordPress, because Pebble is written in Java. I had to learn PHP for WordPress. PHP was easy to learn, because it is based on C.
Each document on my homepage included keywords, and a description for search engines. WordPress is not shipped with a feature to add this information. I compensated with multiple categories. I replaced keywords with categories.
Where’s the Tags?
Google uses categories and tags to determine search results. See the rich snippets on this page for an example.
A WordPress post should have 1 category and 1 or more tags. I noticed that my old posts had multiple categories recently. This is how I fixed it.
How to Find Posts with Multiple Categories
I wrote a PHP function to check a WordPress blog for posts with multiple categories. It can be used as a standalone page.
Code is available from my first Github Gist, and included below. I will explain a few lines.
Line 29 reads the IDs of all published posts.
Line 40 uses get_the category() to read a post’s categories
Line 42 tests for multiple categories
Updated November 28, 2014
- Removed Exceptions.
- Ignore unlikely post without a category.
- Display message if no posts were found.
How to Test Your WordPress Blog
Another Way to Test Your WordPress Blog
Siniša Kolundžić uses more SQL, and gets a different result. See How to count posts in multiple categories for WordPress for his version.
Use either version to remove multiple categories from your posts.