I am developing a custom plugin that adds a new product entity with its own tables to the database.

I would like to perform custom queries on those products through a custom search form -the classic search input with "advanced search" options-.

The results should be displayed in a list, with links to individual items.

What would be considered a best practice for implmenting both plugin and theme?

I have thought of writing a plugin that performs all CRUD oeprations, and a custom theme to display the results:

  • The plugin will add backend forms to let the admin perform basic operations on products.

  • The theme will include myproduct-results.php and myproduct.php templates to render both search results and individual products.

  • The search box and advanced search options will be rendered throug shortcodes written in funcions.php inside the theme.

Are there better options to make the plugin and template be as independant to each other as possible?

Are there any design patterns that provide general guidance on separation of concerns relative to Wordpress plugins and themes development?

  • 1
    Your question is really board, very difficult to give an answer. I would put all the stuff in a plugin, including templates and, specially, shortcodes forms, but allowing the theme to override the templates and shortcode output. That way your plugin can be used on any theme.
    – cybmeta
    Apr 29, 2015 at 10:13
  • 1
    It sounds like you're unaware of custom post types which provide most of what you're wanting already, all you'd need to do is implement the templates, plug a forms fields into a WP_Query object, and add in custom meta fields in the edit screen..
    – Tom J Nowell
    Apr 30, 2015 at 0:54

1 Answer 1


I think you're over thinking things. I'd simply create a new Custom Post in the plugin. That will come with it's own backend automatically.

You can then create the individual pages based on the Template Hierarchy for both the listings and individual pages.

For any additional fields you need, you can either set the meta fields to show on the backend or add them via a plugin such as Advanced Custom Fields

Amend wp-query when searching to do queries on your metadata.

That should be enough to get you going.

I personally don't like the way WordPress does things, so I'm not sure exactly how much separation you will be able to achieve. But a good rule of thumb I find is to try and use the built in functions as much as possible, rather than building your own solution.

  • 2
    Couldn't agree more. No sense trying to re-invent the wheel, when WP will do all the heavy lifting for you. In terms of design patterns, its really not possible to answer this without having all the information about the project. If you're extending a themes functionality/design, then there's no reason why you shouldn't just build a child theme and extend it that way. No need to make a separate plugin for function, when you're only designing for the parent theme anyway. However, whenever I do function extension, I like to do it in classes because a) name-spacing b) code portability. Apr 30, 2015 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.