Do You Have WordPress Posts with Multiple Categories?

WordPress I created my first “homepage” in 1995.

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

The Lucas Problem puzzle was my first CGI program. I showed this puzzle to every person I met in 1995, 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. First, I tried Pebble before WordPress, because I am a Sun Certified Java Programmer, and 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. Who knew? I replaced my keywords with categories, until I learned how to write a plugin that added keywords and description to document headers.

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
Finally: 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

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

Siniša Kolundžić used more SQL, and got a different result. See How to count posts in multiple categories for WordPress for his version.

It does not matter which program you use to remove multiple categories from your WordPress posts.

But do it now, for better search results and a nicer interface for your blog’s visitors.