Custom Field Number 0 different than Null
This topic contains 17 replies, has 4 voices, and was last updated by ian bran 6 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: snippet
-
AuthorPosts
-
July 10, 2018 at 11:22 pm #437823
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. 70Suppose 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 :SHope I could explain myself, thank you very much
July 11, 2018 at 7:41 am #4378641. might be possible with custom CSS, please send over the page with the value and we can see if it is possible.
July 11, 2018 at 3:15 pm #437982This reply has been marked as private.July 12, 2018 at 4:04 am #438069This reply has been marked as private.July 12, 2018 at 3:56 pm #438158This reply has been marked as private.July 13, 2018 at 6:18 am #438214Hi 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!
July 13, 2018 at 7:07 am #438224Hello,
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,
KiranJuly 13, 2018 at 10:15 am #438237Hi 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
July 13, 2018 at 7:18 pm #438312Hello 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
July 13, 2018 at 10:55 pm #438336Hello Alex, I got it! just need add the equal >=
in custom_fields_output_functions.phpgeodir_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 );
July 14, 2018 at 5:18 am #438359This reply has been marked as private.July 14, 2018 at 6:09 am #438362forgot to set private
July 14, 2018 at 6:10 am #438363This reply has been marked as private.July 14, 2018 at 7:40 am #438373This reply has been marked as private.July 14, 2018 at 4:40 pm #438439This reply has been marked as private. -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket