• Hello Fellas and Fellettes,
    I don’t have a page to link to, this is a hypothetical that involves creating custom fields for a custom post type called “stores”. Among the custom fields should be a physical address (street1, street2, city, state, zip).
    Those are five fields that comprise the physical address, and I have yet to run across an explanation or an example of how to define them as a group, among other fields for the “store” type post.

    Why would I not just have a text-area in which the address is filled in freeform?
    Because I want to be able to reference city, state and zip independently in support of searches.

    I also have a custom post type called “products”, and at some point I’m going to want to correlate stores with products, and products with stores (a bidirectional cross reference). There too, I can’t find or I don’t know what to search for, to get a reasonable explanation of how to do that. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If you keep each address line separate, then they are separate entities within the post. You can still output all the lines as a group. But you’d need to get each line separately, then string them together within a single div container.

    WP doesn’t really have a formal way to relate a post type to another type, especially as a 2-way relation. However, if both posts are non-hierarchical, we can cheat a little bit by storing the other post’s ID in the “parent” property of the post object. This is how attachment posts relate to posts and pages. But this only works with a 1:1 relation. For many:many relations you can either keep an array of relations in postmeta or relate them by a common taxonomy term. A custom relations table is also a possibility. Similar to how posts are related to taxonomy terms.

    Thread Starter charlesluck59

    (@charlesluck59)

    Hello bcworkz,
    That was a useful response, and I am grateful.
    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Fields and a Physical Address’ is closed to new replies.