Do You Have WordPress Posts with Multiple Categories?

WordPress I created my first “homepage” in 1995.

I used RCS for revision control, the C Programming Language for CGI programs.

My first CGI program was The Lucas Problem puzzle. I showed it to everyone who was connected to the Internet.

HTML 3.2 improved the Web with tables. Nested tables filled the Web for years. My 2003 homepage was still a table. I changed my homepage content once or twice a year.

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.

I started this blog in 2007, with WordPress 2.1.

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?

WordPress 2.3 introduced tags. I did not use tags for a year. I did not understand why I needed tags, and my theme did not support them.

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

Download mdm_wp_multiple_categories.php. Upload this file on your Web site and run it. My function sends plain text, not HTML. Use it with cURL on command line.

Another Way to Test Your WordPress Blog

After I shared my Gist on Google+, Gregory Karpinsky shared info about an alternative version.

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.