I have a Taxonomy called City, Custom Post named School and i have city names as taxonomy terms. Now i want to display schools[custom posts] from a single term [city]. I have searched and found the only option out there is by creating template files with names:
taxonomy-{taxonomy}-term.php
or
taxonomy-{taxonomy}.php
to display a particular taxonomy.
problem is i have 30 terms, that's saying i must write 30 templates of
taxonomy-{taxonomy}-term.php
to display that term while praying there will be no more cities to add. I think that is not a good way of doing it. Can someone pls help?
Asked
Active
Viewed 183 times
0

Daniel Chikaka
- 1,432
- 4
- 17
- 28
-
Are you unable to just use the custom post query for tax_query() listed here? http://codex.wordpress.org/Taxonomies#Querying_by_taxonomy – Robert Lee Apr 03 '14 at 14:54
-
i saw it , but it has been hard coded. How can i make taxonomy name and term name to be dynamic and avoid the need of writing directly their names in templates? @RobertLee – Daniel Chikaka Apr 03 '14 at 15:14
-
Wouldn't the easiest method be using a POST (hyperlink?city=cityname) and using a $GET[city] and create a custom query based on taxonomy with the information you get from the post link? Here is some reference information on how you can accomplish this with your permalink https://codex.wordpress.org/Function_Reference/get_permalink – Robert Lee Apr 03 '14 at 15:23
-
Thanks @RobertLee , it worked. I was thinking far more ahead of myself – Daniel Chikaka Apr 03 '14 at 23:23
1 Answers
0
Their is no need of creating multiple files. I think you have one custom post type in which you have cities as categories.You have selected school and allotted a city to it.If the user clicks first all the cities should display. In your case it is the cities. If then the user clicks on any of the city then it displays the schools present in that city. And if the the user clicks on a school then it should display the school detail.If the case is this then you should create a one taxonomy_(your category name file).php and one single.(your post name file).php. It will work.

Waqas_aamer
- 220
- 1
- 3
- 18