Custom Field Number 0 different than Null

This topic contains 17 replies, has 4 voices, and was last updated by  ian bran 5 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #437823

    ian bran
    Expired Member
    Post count: 122

    Hello Guys,

    If I create a numeric field and the listing has no option for this then the output is “0” instead of “Not Available” or “-” or something else.

    Example: For an event venue, there is:
    1) Capacity of Seated Assistants: eg. Not Available
    2) Capacity of Standing Assistants: eg. 70

    Suppose 1) is not possible (seated assistants is not possible)

    If listing owner doesn’t fill the field when submitting the listing, the output will be “0”.

    Is there a way to show to users “Not Available”?

    * Field has to be numeric for searching purposes
    ** Seems no easy fix as the field doesn’t allow text :S

    Hope I could explain myself, thank you very much

    #437864

    Alex Rollin
    Moderator
    Post count: 27815

    1. might be possible with custom CSS, please send over the page with the value and we can see if it is possible.

    #437982

    ian bran
    Expired Member
    Post count: 122
    This reply has been marked as private.
    #438069

    Kor
    Moderator
    Post count: 16516
    This reply has been marked as private.
    #438158

    ian bran
    Expired Member
    Post count: 122
    This reply has been marked as private.
    #438214

    Kor
    Moderator
    Post count: 16516

    Hi Ian,

    Thanks for your reply. Unfortunately, we don’t really offer assistance with customizations as it falls outside of our support scope and I hope you understand. But I’ll forward this to our developer for a second opinion.

    Thanks!

    #438224

    Kiran
    Moderator
    Post count: 7069

    Hello,

    Use following code snippet to display “Not Available” instead of empty or 0 value for particular field.

    
    
    function _gd_custom_set_not_available( $html, $location, $cf, $p = '' ) {
    	if(is_int($p)){$post = geodir_get_post_info($p);}
        else{ global $post;}
    
    	if ( ! empty( $post ) && in_array( $cf['htmlvar_name'], array_keys( (array) $post ) ) ) {
    		$field_value = $post->{$cf['htmlvar_name']};
    
    		if ( $field_value === NULL || $field_value === '' ) {
    			$value = __( 'Not Available', 'geodirectory' ); // null or empty
    		} else if ( $field_value === 0 || $field_value === '0' ) {
    			$value = __( 'Not Available', 'geodirectory' ); // 0 (zero)
    		} else {
    			$value = $field_value; // > 0
    		}
    
    		$class = ($cf['htmlvar_name'] == 'geodir_timing') ? "geodir-i-time" : "geodir-i-text";
    		$field_icon = geodir_field_icon_proccess($cf);
    		if (strpos($field_icon, 'http') !== false) {
    			$field_icon_af = '';
    		} elseif ($field_icon == '') {
    			$field_icon_af = ($cf['htmlvar_name'] == 'geodir_timing') ? '<i class="fa fa-clock-o"></i>' : "";
    		} else {
    			$field_icon_af = $field_icon;
    			$field_icon = '';
    		}
    
    		$html = '<div class="geodir_more_info ' . $cf['css_class'] . ' ' . $cf['htmlvar_name'] . '" style="clear:both;"><span class="'.$class.'" style="' . $field_icon . '">' . $field_icon_af;
    		$html .= (trim($cf['site_title'])) ? __($cf['site_title'], 'geodirectory') . ': ' : '';
    		$html .= '</span>';
    		$html .= $value;
    		$html .= '</div>';
    	} else {
    		$html = '';
    	}
    	
    	return $html;
    }
    add_filter( 'geodir_custom_field_output_text_var_geodir_capacity', '_gd_custom_set_not_available', 10, 4 ); // Replace "geodir_capacity" with your field name

    NOTE: Replace “geodir_capacity” with your field name in last line of snippet

    Thanks,
    Kiran

    #438237

    Alex Rollin
    Moderator
    Post count: 27815

    Hi Ian,

    I know you have been trying to make some sort of visually interesting way of showing listing options like AC and the link.

    I was thinking about that and remembered another snippet provided awhile ago for radio buttons.

    Why don’t you take a look and see if it might meet your needs.

    https://wpgeodirectory.com/support/topic/replace-radion-button-selections-with-images/#post-428690

    Let us know how it goes

    #438312

    ian bran
    Expired Member
    Post count: 122

    Hello Kiran, thank you so much for sharing that code.

    It works great in More Info Tab fields, but not for my table, I know this is too far for support…

    The template for the table is inserted from:

    
    
    add_action('geodir_after_description_on_listing_detail', 'gd_profile_custom_content');
    function gd_profile_custom_content() {
    	global $post;
        if ($post->post_type=='gd_place') {
            get_template_part( 'cyctemplates/pagperfil', 'detalles' );
        }	
    }

    and the Table data like this:

    <td ><?php echo geodir_get_post_meta( $post->ID, 'geodir_min_asistentes_banquete', true ); ?></td>

    perhaps I should add something in the table data, but can’t think of what.

    Thank you and if you leave this topic here is completely understood

    #438336

    ian bran
    Expired Member
    Post count: 122

    Hello Alex, I got it! just need add the equal >=
    in custom_fields_output_functions.php

    
    
    geodir_cf_multiselect {
    ...
    
     if (count($option_values) >= 1) {
                    $html .= '<ul>';
    ...

    I’ve copied the file and pasted it under supreme-directory/geodirectory (also tried supreme-directory/geodirectory/geodirectory-functions) and it’s preferring to grab the original template. Seems like only geodirecotry-templates can be replaced in this way.

    My attempt of a filter doesn’t work, maybe this is wrong:

    add_filter( 'geodir_custom_field_output_multiselect_var_geodir_cf_multiselect', '_gd_custom_multiselect_output', 10, 3 );

    whole filter:

    
    
    function _gd_custom_multiselect_output( $html, $location, $cf ) {
    	// If not html then we run the standard output.
        if(empty($html)){
    
            if (!empty($post->{$cf['htmlvar_name']})):
    
                if (is_array($post->{$cf['htmlvar_name']})) {
                    $post->{$cf['htmlvar_name']} = implode(', ', $post->{$cf['htmlvar_name']});
                }
    
                $field_icon = geodir_field_icon_proccess($cf);
                if (strpos($field_icon, 'http') !== false) {
                    $field_icon_af = '';
                } elseif ($field_icon == '') {
                    $field_icon_af = '';
                } else {
                    $field_icon_af = $field_icon;
                    $field_icon = '';
                }
    
                $field_values = explode(',', trim($post->{$cf['htmlvar_name']}, ","));
    
                if(is_array($field_values)){
                    $field_values = array_map('trim', $field_values);
                }
    
                $option_values = array();
                if (!empty($cf['option_values'])) {
                    $cf_option_values = geodir_string_values_to_options(stripslashes_deep($cf['option_values']), true);
    
                    if (!empty($cf_option_values)) {
                        foreach ($cf_option_values as $cf_option_value) {
                            if (isset($cf_option_value['value']) && in_array($cf_option_value['value'], $field_values)) {
                                $option_values[] = $cf_option_value['label'];
                            }
                        }
                    }
                }
    
                $html = '<div class="geodir_more_info ' . $cf['css_class'] . ' ' . $cf['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                $html .= (trim($cf['site_title'])) ? __($cf['site_title'], 'geodirectory') . ': ' : '';
                $html .= '</span>';
    
            //Comentario - Cambio
                if (count($option_values) >= 1) {
                    $html .= '<ul>';
            //Fin        
                    foreach ($option_values as $val) {
                        $html .= '<li>' . $val . '</li>';
                    }
    
                    $html .= '</ul>';
                } else {
                    $html .= __($post->{$cf['htmlvar_name']}, 'geodirectory');
                }
    
                $html .= '</div>';
            endif;
    
        }
    
        return $html; }
    add_filter( 'geodir_custom_field_output_multiselect_var_geodir_cf_multiselect', '_gd_custom_multiselect_output', 10, 3 );
    #438359

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #438362

    ian bran
    Expired Member
    Post count: 122

    forgot to set private

    #438363

    ian bran
    Expired Member
    Post count: 122
    This reply has been marked as private.
    #438373

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #438439

    ian bran
    Expired Member
    Post count: 122
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 18 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket