• Hi there,

    I used this code in my child theme functions.php on my site and it worked great but it suddenly stopped working for some reason. Thoughts?

    Code was supposed 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.

    https://github.com/copyblogger/agentpress-listings/issues/6

    Any thoughts on how to get this working again?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Nick C

    (@modernnerd)

    @withacause That code is still working for me if I replace the property_details_shortcode() function in the AgentPress Listings plugin.

    Or you can use this version in your theme’s functions.php:

    add_shortcode( 'property_details_new', 'property_details_shortcode' );
    function property_details_shortcode( $atts ) {
    
    	global $post, $_agentpress_listings;
    
    	$output = '';
    
    	$output .= '<div class="property-details">';
    
    	$output .= '<div class="property-details-col1">';
    		foreach ( (array) $_agentpress_listings->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) $_agentpress_listings->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;
    
    }

    You will then need to use [property_details_new] for your shortcode instead of [property_details].

    Thread Starter withacause

    (@withacause)

    Thank you, Nick! Once I placed the code in the plugin instead of the theme functions it worked. Thank yoU!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide Empty Property Details’ is closed to new replies.