Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

[property_details] shortcode output #6

Open
dreamwhisper opened this issue Jan 31, 2014 · 0 comments
Open

[property_details] shortcode output #6

dreamwhisper opened this issue Jan 31, 2014 · 0 comments

Comments

@dreamwhisper
Copy link

Chris Cree shared code to hide empty fields in the [property_details] shortcode for single listing page. So, for example, if Basement isn't filled in, it isn't output in the shortcode.

    function property_details_shortcode( $atts ) {

        global $post;

        $output = '';

        $output .= '<div class="property-details">';

        $output .= '<div class="property-details-col1">';
            foreach ( (array) $this->property_details['col1'] as $label => $key ) {
                $value = get_post_meta($post->ID, $key, true);
                if ( !empty( $value ) ) {
                    $output .= sprintf( '<b>%s</b> %s<br />', esc_html( $label ), esc_html( get_post_meta($post->ID, $key, true) ) );
                }   
            }
        $output .= '</div><div class="property-details-col2">';
            foreach ( (array) $this->property_details['col2'] as $label => $key ) {
                $value = get_post_meta($post->ID, $key, true);
                if ( !empty( $value ) ) {
                    $output .= sprintf( '<b>%s</b> %s<br />', esc_html( $label ), esc_html( get_post_meta($post->ID, $key, true) ) );
                }   
            }
        $output .= '</div><div class="clear">';
            $output .= sprintf( '<p><b>%s</b><br /> %s</p></div>', __( 'Additional Features:', 'apl' ), get_the_term_list( $post->ID, 'features', '', ', ', '' ) );

        $output .= '</div>';

        return $output;

    }

Ref: http://wordpress.org/support/topic/shortcode-mod-to-hide-empty-fields

Initially tested to be working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant