Results 1 to 1 of 1

Thread: Hiding Custom Fields that Contain a Certain Text String

  1. #1
    Thread Starter
    mnio's Avatar
    Join Date
    Feb 2013
    Location
    Australia
    Posts
    59
    Thanks
    35
    Thanked 2 Times in 2 Posts

    Hiding Custom Fields that Contain a Certain Text String

    Hi there

    Just wondering if anyone can assist in hiding custom fields on the listing page that contain a certain string. I'd like to hide all those that contain "N/A"

    I'm assuming this code (from template-tags.php) needs to be modified and included in my functions.php

    Code:
    /**
     * Displays listing fields.
     *
     * @param int $listing_id (optional)
     *
     * @return void
     */
    function the_listing_fields( $listing_id = 0 ) {
    	$listing_id = $listing_id ? $listing_id : get_the_ID();
    
    	$cats = array_keys( get_the_listing_categories( $listing_id ) );
    	if ( ! $cats ) {
    		return;
    	}
    
    	$fields = array();
    	foreach ( $cats as $cat ) {
    		foreach ( va_get_fields_for_cat( $cat, VA_LISTING_CATEGORY ) as $field ) {
    			$fields[ $field['name'] ] = $field;
    		}
    	}
    
    	foreach ( $fields as $field ) {
    		if ( 'checkbox' === $field['type'] ) {
    			$value = implode( ', ', get_post_meta( $listing_id, $field['name'] ) );
    		} else {
    			$value = get_post_meta( $listing_id, $field['name'], true );
    		}
    
    		if ( ! $value ) {
    			continue;
    		}
    
    		$wrapper = 'span';
    
    		if ( 'textarea' === $field['type'] ) {
    			$wrapper = 'div';
    			$value = nl2br( $value );
    		}
    
    		$field['id_tag'] = va_make_custom_field_id_tag( $field['name'] );
    
    		echo html( 'div', array( 'class' => 'listing-custom-field', 'id' => $field['id_tag'] ),
    			html( 'span', array( 'class' => 'custom-field-label' ), $field['desc'] ). html( 'span', array( 'class' => 'custom-field-sep' ), ': ' ) . html( $wrapper, array( 'class' => 'custom-field-value' ), $value ) );
    	}
    }

    Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Increase Text Size of Custom Fields
    By tigerx51v in forum ClassiPress General Discussion
    Replies: 0
    Last Post: May 29th, 2015, 08:24 PM
  2. Add supporting text next to the Default Custom Fields
    By rufuspinho in forum Help Using Vantage (Legacy)
    Replies: 5
    Last Post: April 16th, 2015, 11:17 AM
  3. How do i make text bold in custom fields?
    By naz1887 in forum Vantage General Discussion (Legacy)
    Replies: 4
    Last Post: November 25th, 2013, 01:46 PM
  4. Hiding custom fields from published ad
    By popeye in forum ClassiPress General Discussion
    Replies: 11
    Last Post: March 9th, 2012, 02:58 PM
  5. How can 'fixed text' instruction-fields be added to custom form
    By swapmama in forum ClassiPress General Discussion
    Replies: 3
    Last Post: August 23rd, 2011, 01:38 PM