Home › Forums › General Issues › Display fields on single posts of custom taxonomy term
HI, I’m trying to display fields only on single posts with a specific term of a custom taxonomy of a custom post type. The CPT is attractions, the taxonomy is attractiontype, the term is tours, and the term ID 239. I’ve tried every combination I think of, with varying degrees of success (some work on the single, but not on the archive; some on the archive, but then show on all posts. Below I’m showing it with just is_singular… but I’ve tried it with !is_singular, !is_single, is_single, has_tag, has_term and every combination of all of them I can think of. 🙁 The fields themselves show up just fine – I’m just having trouble getting them to ONLY show on the tagged tours posts.
Am I doing something wrong?
add_action( 'genesis_post_content', 'theme_prefix_tour', 12 );
function theme_prefix_tour() {
// Return early if not a single page with tours tag
if ( is_singular( 'attractions' ) && has_term ( 'tours', 'attractiontype' ) )
return;
// Store the tour data
$tour_data = array(
'contact' => get_field( 'contact' ),
'admission' => get_field( 'admission' ),
'hours' => get_field( 'hours' ),
'coaches_accepted' => get_field( 'coaches_accepted' ),
'reservations_required' => get_field( 'reservations_required' ),
'length_of_tour' => get_field( 'length_of_tour' ),
'location_of_parking' => get_field( 'location_of_parking' ),
'comp_policy' => get_field( 'comp_policy' ),
'restrooms_available' => get_field( 'restrooms_available' ),
'dietary_menu_available' => get_field( 'dietary_menu_available' ),
);
// Only output if we have tour data
if( $tour_data ) {
echo '<div class="details">Tour Information</div>';
echo '<div class="location-wrap one-half first">';
if ( $tour_data['contact'] ) {
echo '<div class="location">' . esc_attr( $tour_data['contact'] ) . '</div>';
}
if ( $tour_data['admission'] ) {
echo '<div class="location">' . esc_attr( $tour_data['admission'] ) . '</div>';
}
if ( $tour_data['hours'] ) {
echo '<div class="location">' . esc_attr( $tour_data['hours'] ) . '</div>';
}
if ( $tour_data['coaches_accepted'] ) {
echo '<div class="location">' . esc_attr( $tour_data['coaches_accepted'] ) . '</div>';
}
if ( $tour_data['reservations_required'] ) {
echo '<div class="location">' . esc_attr( $tour_data['reservations_required'] ) . '</div>';
}
if ( $tour_data['length_of_tour'] ) {
echo '<div class="location">' . esc_attr( $tour_data['length_of_tour'] ) . '</div>';
}
if ( $tour_data['location_of_parking'] ) {
echo '<div class="location">' . esc_attr( $tour_data['location_of_parking'] ) . '</div>';
}
if ( $tour_data['comp_policy'] ) {
echo '<div class="location">' . esc_attr( $tour_data['comp_policy'] ) . '</div>';
}
if ( $tour_data['restrooms_available'] ) {
echo '<div class="location">' . esc_attr( $tour_data['restrooms_available'] ) . '</div>';
}
if ( $tour_data['dietary_menu_available'] ) {
echo '<div class="location">' . esc_attr( $tour_data['dietary_menu_available'] ) . '</div>';
}
echo '</div>';
}
}
Hi @ameeker
Sounds like the issue is not to do with ACF, but more of a general WP question.
I would advise you to ask this question on stack overflow and please debug your function by dumping out the returned data of these if statement functions.
Thanks
E
The topic ‘Display fields on single posts of custom taxonomy term’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.