How to Build a Movie Library in WordPress 3.x

Plugin vs. Theme vs. MU-Plugin vs. Drop-In

»Would this application require building a plug-in, or just adding code to my theme?«

Basically all four are the same. They differ only in two points:

  1. Location and

    • MU-Plugins are in the mu-plugins folder 1)
    • Plugins are in the plugins directory
    • Drop-Ins live in the wp-content folder as single files outside of folders
    • Themes are in the themes directory and/or any other directory you registered via register_theme_directory(); (which should be done in a drop-in).
  2. Loading order and therefore access to wordpress hooks.

    • MU-Plugin – can access 'muplugins_loaded'
    • Plugin & Drop-In – can access 'plugins_loaded'
    • Theme – can access 'after_theme_setup'

… and later hooks.

Custom Post Types

»Would each actor’s page be treated as a “page” or would it be treated as a post?«

WordPress comes – out of the box – with some built in post types

  • Post
  • Page
  • Attachment/Media
  • Link
  • Nav Menu Item

But you got the possibility to add your own CPTs 2). Just read the linked Codex article on how to setup your own CPTs of Movie/Actor or use a set of classes as a base, like this great one (incl. a tutorial) by Toscho.

Custom Taxonomies

WordPress also got built in Taxonomies

  • Categories (hierarchical)
  • Tags (non-hierarchical)
  • Link Category (for links post type)
  • Post Format (for post post type)

Templates and Themes

»For the actor pages, where would the query go that retrieves the list of movies?«

WordPress got the Template Hierarchy. Basically it’s two things:

  1. A routing mechanism – tells which theme file to load – if it exists
  2. A query altering mechanism – tells which files to load

This post by @Rarst will tell you the basics about how to alter the WP_Query to get exactly those posts that you want, when WP doesn’t already deliver it by you request.

Standard installations stripped

Sometime you might want to reduce WP a bit to get a cleaner interface for your APP. Just take a look at WP Strip Naked as a starting point.

If you got additions for the plugin, just leave a comment, or – even better – change it and make a pull request on github.

Post Relationships

Posts2Posts is the way to go if you need to interconnect posts or CPTs. Trying to deal with it without the plugin makes actually no sense, as the author is core contributer and constantly cares about developing it further.

Special Purpose Meta Boxes

When you need special fields for your post types, then you better use a library like for example the RW_Meta_Box class set. As with the Posts2Posts Plugin, it makes no sense to try to get around this yourself – it’s not worth the effort 3).

Altering the search

»When the search form is submitted, where is the script located that would process the search request?«

In general, WP has built in stuff (called template tags) to display the searchform, the search results page, etc.

There’s already another answer, where I wrote about this in detail. The approach can be adapted to fit your use case.

Hooks & Filters

In many cases you might want to use a hook or filter in your themes functions.php or a plugin file, instead of altering the output. Generally said, it’s a way to modify stuff on the flight and on demand. This helps making your APP more performant plus keeps code outside your templates. Pleas just read more about this topic in the Codex.

Alternative approach with plugins

As always for special cases, you got PODS for the rescue. This plugin is the swiss army knife for all sorts of special purpose content types. Plus it got built in relation ships with custom as well as built in stuff (from users to post types).

Footnotes

1) »One thing to note is that the Must Use Plugins don’t work like regular plugins which are typically each stored in their own directory with one file that contains a plugin header. With MU plugins WordPress only looks in the mu-plugins directory for .PHP files and not for files in subdirectories so if you want to move regular plugins over to the MU plugins directory you’ll probably need to create a proxy .PHP file. That file should contains a PHP require_once() to include the plugin’s main .PHP from its subdirectory, or you can create a single .PHP file with a require_once() for each of the plugins you have in the mu-plugins directory.« Mike Schinkel on hakres blog on MU-Plugins topic

2) CPT is short for Custom Post Type

3) I dropped the development of my own set of classes about 2 month ago and invested my time into Rilws/Anhs library. The development is going fast and we reply to nearly every pull request with a “Thank you”.