How to Display Pods Fields in Custom Taxonomy Templates
-
I have been assigned the task of creating a website that showcases the various menus of a restaurant. Each menu will have it’s own page to display the title, price and (on the dinner menu page) a short description; all classified under their own sub headers (i.e. on the Dinner page there will be “Seafood” header and the Title, description and price for all Seafood plates).
After giving some thought to my data, I decided that I would use PODS to create two custom content types called “Food” and “Drink”. And, I would create one custom taxonomy called “Menu”. I would then assign the Menu taxonomy to both the Food and Drink content type.
The reasoning behind using a taxonomy as opposed to a relationship is two fold:
1. I wanted for the client to be able to add their own menus should they decide to expand their offerings (for example, adding a cocktail menu or a dessert menu). If I can get his done right I should be able to assign a WordPress template to dynamically display drinks or food for any of the menu categories.
2. The category system is a familiar user interface so it’s a smaller learning curve for those experienced with using WordPress.Here is an example of the cateogry/slug structure:
Parent Category **Beer** – slug: [domain]/menu/beer/
* Child Category: On Tap – slug: [domain}/menu/beer-on-tap/
* Child Category: Bottles – slug: [domain}/menu/beer-bottles/On the front-end, if a visitor goes to: [domain]/menu/beer/ the site will display a list of all the “drink” posts classified under beer.
There are two key questions which I have been unable find the answer to:
1. Using my taxonomy-menu.php template, list the posts using their child category
titles as headings?
2. How do I display PODS custom fields in the taxonomy-menu.php template?Any help in answering the above questions would be greatly appreciated.
BTW. I was encouraged by a PODS forum post ([Auto Template for Custom Taxonomy – Pods Framework](https://pods.io/forums/topic/auto-template-for-custom-taxonomy-2/)) that described a similar situation and gave example code to check for the taxonomy via the slug using the following code but it didn’t work for me:
`
$taxonomy = get_queried_object(); // get the current queried taxonomy object
$theterm = $taxonomy->slug; // assign a variable to the taxonomy’s slug// configure the params of your pods->find
$params = array(
‘limit’ => -1,
‘where’ => “YOUR_TAXONOMY_NAME_HERE.slug = ‘$theterm’”
);
`
- The topic ‘How to Display Pods Fields in Custom Taxonomy Templates’ is closed to new replies.