Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Creating an archive page or simple template to list all values of a custom field of specific post type listing

The first thing I would do, if I were you, would be to change the data structure so that the location would a hierarchical custom taxonomy where states were parent terms and cities their child terms.

Then you could create a custom taxonomy template for your location taxonomy. In this template you’d display list of child terms when the queried object is a parent term.


EDIT 3.9.2019

Here is a very basic example how to get the child terms in archive-{post_type}.php template

// WP_Term object
$current_term = get_queried_object();
// maybe array of WP_Term objects
$children = get_terms( array(
  'taxonomy' => $current_term->taxonomy,
  'parent'   => $current_term->term_id
) );
// If any child terms exists
if ( $children && ! is_wp_error( $children ) ) : ?>
  <ul>
    <?php foreach ( $children as $child_term ) : ?>
      <li><?php echo esc_html( $child_term->name ); ?></li>
    <?php endforeach; ?>
  </ul>
<?php endif; 

A good place to learn more about custom post types is the Plugin Handbook, https://developer.wordpress.org/plugins/post-types/working-with-custom-post-types/

And if you’re not very familiar with PHP yet, have a look at the PHP documentation Getting Started guide, https://www.php.net/manual/en/getting-started.php, or use your preferred search engine to find tutorials and beginner level courses.

Related Posts:

  1. what is the correct way to compare dates in a WP query_posts meta_query
  2. Advanced search form with filters for custom taxonomies and custom fields
  3. Custom Post Type Archives by Year & Month?
  4. Get custom post type slug for an archive page
  5. Custom field values deleted when trashing custom post type
  6. How to get all custom fields of any post type
  7. Meta_Query as a way how to setup CPT permalinks – is it a good thing?
  8. Admin Area Custom Type Search By Meta Fields Without Title & Content
  9. How do I Paginate Search Results for Custom Post Types?
  10. Proper way of making custom post type landing page or archive page
  11. Custom Post Type Archives by Date with Custom Permalink
  12. Change title in head on Archive page
  13. Custom Post Type Archives with 0 Posts Redirects as 404
  14. How to filter custom post type archive by meta value
  15. Page is defaulting to archive page and not designated template
  16. How Can I save multiple records in same meta key?
  17. Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
  18. Detect meta value changes when post is updated (post_updated)
  19. Search everything (posts, pages, tags, cpt, meta)
  20. Rewrite custom post type url’s adding meta box values
  21. I can’t set meta_key in my custom post type query
  22. Compare 3 custom fields and sort by oldest
  23. paginate function in archive for custom-post-type
  24. How to get source of custom meta image?
  25. Custom post type archive sorted and grouped by date in post meta field
  26. Displaying Meta Box Image
  27. How to create archive page for taxonomy terms within custom post type
  28. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  29. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  30. WordPress custom post type archive with description
  31. Custom-post-type-archive: posts sorted/filtered by year?
  32. How to list custom post types?
  33. Custom post type archive page pagination
  34. Editable content on a Custom Archive page
  35. Second Custom Post Type Archive
  36. Create a random unique 6 digit number as custom field for custom post type
  37. how to interconnect custom post types?
  38. is_main_query() not working for WP REST API
  39. List all images from a single post meta value
  40. Populate Custom Fields in a Custom Post Type?
  41. CPT Archive with core Category
  42. Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
  43. get the custom post type title/name
  44. Meta Key Value in current-user-only loop
  45. How to check if user meta field is empty in conditional else statement
  46. URL of a custom post type’s post format archive?
  47. How to implement a Google map store locator
  48. Create template for taxonomy results limited by Custom Post Type
  49. Posting to a Custom Post Type from front end – user generated content
  50. Update Post Meta for a logged in user
  51. A better way to add a meta box to custom post types
  52. Two Custom Post Types Many to Many Relationship
  53. get_post_meta not working on publishing
  54. How do I set all of a particular post meta to a value within the custom post type I’m in?
  55. Custom post type archive page blank
  56. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  57. How to display custom post in archive section of the wordpress page?
  58. Importing Data from a Non-WordPress database, into WP
  59. Custom fields for custom post type
  60. Check if post with same meta value exists
  61. What’s the name of the custom post type yearly archive template?
  62. Archieve.php not loading for custom post type
  63. Submitting Custom Post Types with custom fields from Front-end form
  64. create custom meta box with default value
  65. How can I use archive-{post_type}.php theme template?
  66. Return the name of the post type
  67. Custom Post type page content (archive page)
  68. Group custom post type posts by month
  69. How can I add a meta[] to my custom post type and search by term with the Rest API?
  70. Show posts from WP Custom Post Type selected from a field in a metabox
  71. Where is get_post_meta value located?
  72. Custom meta fields not showing up in WP_Response Object via custom endpoint
  73. Do not show child pages within a file page
  74. Tell wordpress to show a single page instead of an archive page
  75. Custom Post Type archive page listing a 404 or single post
  76. How to Disable option of meta field if that option is selected for any other post in custom post type?
  77. Meta_query by date for Events archive
  78. Add more custom fields when creating a new custom post type
  79. How do I extract the contents of a CPT’s custom field for all posts?
  80. Want to display my custom date archive to date.php but dont know how
  81. Delete custom post type metadata without deleting the post in admin area
  82. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  83. Rewriting archive page slug to be different than custom post type slug
  84. How to add post reference field to a plugin?
  85. Site loads very slow for archive custom post type page
  86. Stop Custom post type from being searched via URL
  87. Custom post type category page not working
  88. paging is not working properly on news archives page [duplicate]
  89. How can I set up the URL for a category archive for a custom post type?
  90. Taxonomy Query of Custom Post Displays Archive Instead of Posts
  91. Advanced search form with filters for custom taxonomies and custom fields
  92. Querying meta values within an array
  93. Pagination not working for archive
  94. How to have a dynamic slug and rendering the archive-{post_type}.php?
  95. Remove plugin’s custom post type archive page and single pages [closed]
  96. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  97. Check for custom field value in different post type than current one and do something
  98. WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
  99. WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query
  100. Remove date rewrite rule for custom post type archive page
Categories custom-post-types Tags archives, custom-field, custom-post-type-archives, custom-post-types, post-meta
When upload a PNG a noise appears in the thumbnails
Cannot publish posts or pages when I change permalink structure

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress