WordPress.org

Ready to get started?Download WordPress

Forums

AgentPress Listings
[resolved] Shortcode Mod to Hide Empty Fields (4 posts)

  1. ChrisCree
    Member
    Posted 1 year ago #

    Heya Ron!

    I was messing with the property_details_shortcode function in the /includes/class-listings.php file to make it not show fields when they are left blank. Here's the code I came up with if you want to incorporate it into the plugin.

    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;
    
    	}

    http://wordpress.org/extend/plugins/agentpress-listings/

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 1 year ago #

    Hey Chris, can you email me that? I won't remember where to find it the next time we're updating the plugin.

  3. ChrisCree
    Member
    Posted 1 year ago #

    Got distracted by Christmas. Just sent it on to you.

  4. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 1 year ago #

    Got it, thanks :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.