1

I am learning Wordpress for the first time since a couple weeks or so, and to make practice and create something useful, I've started a pizza restaurant website, which perhaps I'll also publish.

To explain myself in the shortest possible way, I'm currently editing some of the default MotoPress Restaurant Menu plugin templates to make the site look like I'd want. First, the plugin offered a menu listing template, but I had no idea on how to sort the elements, how to filter them, and how to achieve a table-like display instead of a list of <div>s inside the page. What I did to "improve" this template was creating a custom page-menu-lb.php template file and adding there code for populating a <table> with data from the database.

To fetch the data from the database, instead, I created some files and classes which use Wordpress API function/classes like WP_Query and the (wp)_get_* functions; further, I also modelled a Pizza class to store data in an object-oriented way. With this, I was able to construct a menu page the way I intended.

enter image description here

Now that I also have to display posts for single items (in my case, pizzas) I have to modify other template files of the kind single-{post-type}.php. I know more than a couple of ways to do it, but what is the most idiomatic and "correct" in Wordpress?

My two final questions are therefore:

  1. How should I fetch the data from the database? I saw that internally the plugin does it by calling its own functions - it has a kind of little framework inside. Should I use them, or do I risk upgrades incompatibilities? Or should I limit myself to querying the database by using the WP_Query, wpdb classes and the (wp)_get_* functions?
  2. Should I modify the plugin default templates by implementing action and filter hooks as recommended by the succinct plugin documentation, or create custom templates?
1

I'll answer myself after having completed my two points in the last few days of work:

  1. My plugin, which indeed did all of the data insertion and management work, contained some very handy APIs in its codebase. WordPress does also provide some very great database access APIs (amongst other things) and I can say that I used them interchangeably. In general, I gave priority over the plugin functions, but if I didn't find a useful API it was easy constructing one myself on top of WordPress'. However, I never used direct MySQL queries, like through the wpdb class.

  2. I also needed to define templates for single menu items, which actually were posts. In the only one case so far, I created a single-mp_menu_item.php template file within my child theme directory, and I modified code pasted there from the parent theme to suit my needs. What is important to note though, is that I did not resort to using action and filter hooks as recommended by the plugin documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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