Support Forum
I have created a CPT - 'People'. Each person works in one of two offices - Tampa or St Pete. The office locations are Taxonomy assigned to CPT People. I am using MetaBox AIO and I am not a programmer.
I am having trouble with:
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):
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
}
Yes Tampa and St Pete are taxonomies assigned to CPT People. thanks for help with the script....
quick follow up -
I'm also using Beaver Themer addon and Astra theme. I know that the Themer addon makes this a bit easier, but I need to add leading text before custom meta is displayed in same row - example:
Direct Line: [custom meta field PHONE NUMBER].
So am I able to add the snippet you helped with into a text box or HTML module? or do I need something more advanced to run PHP inside a page or widget?
thanks!
It just occured to me that I may need to share more info about my project. See below:
My People CPT are attorneys. there are about 18 meta fields in use to collect info on each Person that will be used to display when users visit the Profile page.
most info is simple data, but, the People have a few custom items. this work is to make it easy for client to add their own new employees and then to ensure the right info is being displayed on the front end -
if People work in Tampa, I need to display the Tampa address
if People work in St. Pete, I need to display the St. Pete address
also, each of the People CPT are authors for various blog articles, so we are using the Co-Authors plugin to handle that. this is important to mention because in addition to the profile info displayed for each attorney, we also need to display all articles attributed to them.
here is a URL to the live site (uses WCK and a ton of custom code) which we are replicating using MEtaBox - https://www.trenam.com/people-list/paul-d-bain/
Thanks for your details!
Because the Tampa and St. Pete are terms that are connected to People CPT, to get the address, we actually go from post (People) -> taxonomy term (Tampa/St. Pete) -> term field.
So I think the Beaver addon doesn't work. It can only get post field for the current post.
I'd suggest you write a custom shortcode to get the term address. Then you can put it in the Text/Heading field in the Beaver Themer. Adding prefix text is also easy then.
Thanks Anh. I'll let you know how it turns out.