Understanding WordPress Taxonomy Table Relationships

When working with taxonomies in WordPress, it’s helpful to understand the taxonomy database schema. The WordPress database contains three tables for storing taxonomy data:

  • wp_terms – stores all of your taxonomy terms
  • wp_term_taxonomy – defines what taxonomy each term belongs to
  • wp_term_relationships – cross-reference table that joins taxonomy terms with your content

Let’s look at an example database query joining the taxonomy tables. The below query will return all posts with all taxonomy terms assigned to each post:

SELECT wt.name, p.post_title, p.post_date 
FROM wp_terms wt
INNER JOIN wp_term_taxonomy wtt ON wt.term_id = wtt.term_id
INNER JOIN wp_term_relationships wtr ON wtt.term_taxonomy_id = wtr.term_taxonomy_id
INNER JOIN wp_posts p ON wtr.object_id = p.ID
WHERE p.post_type = 'post'

Using joins you can start to understand the relationship between the three taxonomy tables. I’m a visual person, so I created the below graphic to illustrate the taxonomy table relationships.

987247c07f002

Taxonomies are an extremely powerful component of WordPress. Understanding the taxonomy database schema can be very helpful when building more complex WordPress websites. If you are interested in learning more about taxonomies in WordPress, check out my Professional WordPress book.

Professional WordPress Third Edition is Coming!

That’s right, the highest rated WordPress development book on the market is back with an all new third edition! The writing has begun and Professional WordPress 3E has officially passed the halfway mark. Just like the previous edition, this version will be written by David Damstra and myself.

Professional WordPress 3E will be fully updated for WordPress 4.1. The new edition will feature two completely new chapters:

  • Migrating to WordPress – Covers understanding the migration process, generating data mapping guides, and utilizing WP-CLI with migration scripts.
  • Application Framework – Covers using WordPress as an application framework, integrating APIs, external libraries, and web services. Will also touch on native app development on iOS and Android.

As an extra special bonus, we have THE Lisa Sabin-Wilson on board as the Technical Editor for this edition! Lisa is the For Dummies brand franchise author on all things WordPress. She has been working with WordPress since 2003 and writing about WordPress since 2006. Lisa is an amazing asset to have on Professional WordPress and will help make this edition the best one yet!

The book is targeting an end of year release. You can follow our progress and any Professional WordPress Third Edition news with the hash tag #prowp3.

WordSesh 2 Is Live Right Now

WordPress Online ConferenceHave you heard of WordSesh? The online streaming WordPress conference (which is totally free) is currently streaming live right now for WordSesh 2!

WordSesh has two tracks with 58 amazing speakers:

Don’t miss out enjoying this event live. The sessions are recorded, so you could watch them later, but joining in on the chat room and tweet conversations make WordSesh a very special event.

Writing Secure WordPress Code

A few weeks ago I gave a presentation at WordCamp Europe on writing secure WordPress code. The methods I described in my presentation are extremely important when writing code for WordPress. Whether you are a theme designer or a hardcore plugin developer, you should follow all of these security measures to verify your code is as secure as possible. My presentation slides are below:

WordCamp Europe Is Next Week!

Next week I will be attending and speaking at the first ever WordCamp Europe! The event takes place October 5th-7th in Leiden, Netherlands. WordCamp Europe is going to be an amazing event with a insane amount of awesome presentations.

WordCamp Europe 2013 SpeakerI will be presenting on Writing Secure WordPress Code. I’m scheduled to be the last presentation on Saturday at 17:15. I’ll be covering tips and functions available in WordPress that can help you keep your code as secure as possible. Whether you’re a plugin developer or build themes, it’s extremely important to understand how to secure your code from hacks and exploits.

As awesome as this event is going to be, I’m just as excited to see many of my friends at the event. The Attendees list is a who’s who of WordPress awesomeness. I have so many European friends in the WordPress community that will be in attendance so I can’t wait to hang out!

If you’re attending WordCamp Europe make sure you track me down and say hi!

Free WordPress Security Webinar Today

I’ll be hosting a free WordPress Security Webinar Thursday, September 26th at 4pm EDT. The webinar was organized by SiteGround and is available free for anyone to attend. I’ll be hosting the webinar with my WebDevStudios Co-Founder Brian Messenlehner.

If you run a WordPress website and want to learn how to keep your website safe from exploits and hacks, make sure you register to attend!

Do You Want Professional WordPress Plugin Development Second Edition?

Recently I’ve been thinking about my book Professional WordPress Plugin Development, and whether there’s enough demand for a second edition.

Over the years I’ve received some amazing feedback from readers, many of whom have since released plugins on WordPress.org after reading the book. The book is an amazing resource for anyone creating custom plugins in WordPress, from beginners to experts alike. I use the book on an almost daily basis to refresh my memory on proper techniques, functions, and hooks to use when building plugins.

The original Professional WordPress Plugin Development was written for WordPress 3.1, which was released over 2 years ago. The book is still the highest rated WordPress development book on Amazon, with a solid 5-star rating.
pro-wordpress-5-star-reviews

I have two questions for you:

  • Do you want to see a second edition?
  • What would you like to see in a second edition?

I’d love to hear your thoughts in the comments below!

How To: Create a Network Only Plugin in WordPress

If you’ve ever created a custom plugin in WordPress, you should be familiar with the standard plugin header code. The information set in your plugin header is displayed under the Plugins admin menu in WordPress shown below:

wordpress-plugin-header-example

There is a lesser known piece of information that can be defined in your plugin header that tells WordPress to only show your plugin on the WordPress Multisite Network Plugins page. This will hide your plugin from being displayed and activated at the site level in WordPress Multisite. To only allow your plugin to show at the Network Plugins level, simply add this one line to your plugin header code:

Network: true

Easy, right? Let’s look at an example comparing a standard plugin header with a network only plugin header.

Standard Plugin Header:

/*
Plugin Name: My Awesome Plugin
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: This is my extremely awesome WordPress plugin
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
*/

Network Only Plugin Header:

/*
Plugin Name: My Awesome Plugin
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: This is my extremely awesome WordPress plugin
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
Network: True
*/

Using this method you can be sure your WordPress plugin will only be network activated in Multisite.

The First WordSesh Was a Huge Success!

wordsesh-badge-speakingWordSesh, the first ever 24 hour free live streaming WordPress event, took place just a few short days ago. I had the privilege of helping organize and run the event with Scott Basgaard and Chris Cochran. The event was a huge success that featured an epic list of presenters from the WordPress Community.

Below are a few of the presentations that I enjoyed the most:

DradCast Kickoff Episode

Dre and I hosted a special WordSesh kickoff edition of the DradCast hosted by Scott Basgaard. We had a great time discussing how WordSesh was thought up, the logistics behind organizing an online only event, and some fun WordPress news.

Scoping Projects to Avoid Stress, Headaches & Angry Mobs

Lisa gave a great presentation on scoping projects for clients, which is a topic any entrepreneur can benefit from. She shares her experience with a client and ways she could have made the project run smoother by creating a detailed proposal and spec upfront.

WordPress Plugins, Code, and the Ecosystem in General

Brian and Pippin present on plugins and the ecosystem around them. They both have a wealth of knowledge that all WordPress plugins developers could learn from.

Everything & anything you’ve ever wanted to know about BuddyPress & bbPress

John’s presentation on BuddyPress and bbPress is a fun walkthrough on the history of both projects. John discusses the initial releases, journey to their current state, and also touches on the future of both BuddyPress and bbPress.

The best part of WordSesh is that all presentations are available online! To view any of the amazing videos visit the WordSesh YouTube page. Also be sure to follow @WordSesh on Twitter for updates on future events.

WordSesh proved that an online only WordPress event is something the community not only needs, but absolutely loves. Stay tuned for WordSesh 2!

How To: Get the Current Logged in User ID in WordPress

When developing custom themes and plugins for WordPress there are times you will need to get the logged in user’s ID. There are a few different ways to accomplish this, but I’m going to show you the easiest method. To get the user’s ID you’ll use the get_current_user_id() function like so:

$current_user_id = get_current_user_id();
echo 'Your User ID is: ' .$current_user_id;

The get_current_user_id() function will return the currently logged in user’s ID, or 0 if a user is not logged in. Another popular method, which requires a bit more code, is the get_currentuserinfo() function. The method I described above actually uses the wp_get_current_user() function, which is a wrapper for get_currentuserinfo(). So using get_current_user_id() is just a faster method for retrieving the same data. This function was added in WordPress 3.0 as part of the Multisite code merge into WordPress.

To learn more about the get_current_user_id() function check out the Codex article or consult the WordPress core.