[ad_1]
I’m trying to retrieve ONLY the primary term for a custom taxonomy.
There is a primary ‘building_type’ selected, and I’d like to get ONLY the primary one, instead of all the terms checked. Here’s the code I used to get ALL the terms (which works).$termsP = the_terms( get_the_ID(), array( //'building_type', 'lease_phase', 'topic', 'building_stakeholder') );
And here’s what I’m using to try and get the primary building_type:
$post_id = get_the_ID();
$primaryTerms = the_seo_framework()->get_custom_field( '_primary_term_' . 'building_type', $post_id );
I’ve also tried this which also doesn’t work:
$taxonomy = 'building_type';
$post_id = get_the_ID();
$terms = wp_get_post_terms($post_id, $taxonomy, ['fields' => 'all']);
$primary_term = intval(get_post_meta( $post_id, '_primary_term_' . $taxonomy, true ));
foreach($terms as $term) {
if( $primary_term == $term->term_id ) { // this is a primary category } }
return $primary_term;
Any help is greatly appreciated.
- This topic was modified 3 hours, 25 minutes ago by .
The page I need help with: [log in to see the link]
