Support

Account

Home Forums General Issues Display fields on single posts of custom taxonomy term

Solving

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

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Display fields on single posts of custom taxonomy term’ is closed to new replies.