Support General How to use conditional logic and then display custom meta on a page. Reply To: How to use conditional logic and then display custom meta on a page.

#10396
Anh TranAnh Tran
Keymaster

Hi,

Are "Tampa" and "St Pete" terms of the "office location" taxonomy?

If so, you have some ways to store the actual address of each location (each term):

  • Use the default WordPress term's description for actual address (https://i.imgur.com/GIU2Bbb.png). If you don't use the description for any purpose, it's good to use it for address, cause it doesn't require any coding.
  • Or you can use the MB Term Meta extension to add a text field "Address" for "office location" taxonomy. You can use the Meta Box Builder to create that field for you if you're not familiar with coding. Just remember to go to Settings tab and select "Terms" & "Taxonomy" for the setting "Show meta box" for.

After that, you'll be able to enter address for each location ("term") when you edit them.

To show the office address, you can use this snippet:

$locations = wp_get_object_terms( get_the_ID(),  'office_location_taxonomy' );
if ( ! empty( $locations ) && ! is_wp_error( $locations ) ) {
    $location = reset( $locations );
    echo 'Address: ', $location->description; // If you use term description.
    echo 'Address: ', rwmb_meta( 'address_field_id', array( 'object_type' => 'term' ), $location->term_id ); // If you use MB Term Meta
}