0

I have a CPT which saves a location and and its slug into wp_postmeta table. The location is selected from a dropdown in CPT edit page and it is not a taxonomy.

Now I want to create a custom template which needs to understand the value I am passing through the URL such as http://example.com/location/himachal-pradesh.

The part himachal-pradesh is my location slug and I want to pull posts which has the same value in wp_postmeta table.

I have created a custom template and can use it to create a new page (http://example.com/location), but it will actually have the location slug which is dynamic for each location.

What is the right way to achieve this?

  • What you write about is a typical use of custom taxonomy. Replace the custom field location to custom taxonomy, this will improve performance. – nmr Aug 7 at 12:55
  • Thank you for you quick reply. Yes, that is what I will do if there is no other straight forward way. Just wanted to know if there is! :) – Subrata Sarkar Aug 7 at 12:58
  • 1
    The use of a custom field for that is possible, but very very inefficient. If you are going to search or filter posts by some information, it is better to save it as taxonomy. – nmr Aug 7 at 13:05

Your Answer

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

Browse other questions tagged or ask your own question.