Support

Account

Home Forums Backend Issues (wp-admin) Groups and custom columns when filtering

Unread

Groups and custom columns when filtering

  • FYI, some info about Groups and custom columns when filtering. It seems retrieving the Group values won’t work when the admin listings page gets filtered, because that’s creating a ‘post’ and not a ‘get’. Here is the code that i had (which worked great when the listings page rendered:

    			// Display the value of the custom fields in the custom columns
    			public function display_custom_column_content($column_name, $post_id) {
    					$general_info = get_field('general_info', $post_id);
    
    					switch ($column_name) {
    							case 'bedrooms':
    									$value = $general_info['bedrooms'];
    									echo $value ? esc_html($value) : '-';
    									break;
    							case 'bathrooms':
    									$value = $general_info['bathrooms'];
    									echo $value ? esc_html($value) : '-';
    									break;
    							case 'size':
    									$value = $general_info['size'];
    									echo $value ? esc_html(number_format($value) . ' sq. ft.') : '-';
    									break;
    							case 'lot_size':
    									$value = $general_info['lot_size'];
    									echo $value ? esc_html(number_format($value) . ' sq. ft.') : '-';
    									break;
    							case 'price':
    									$value = $general_info['price'];
    									echo $value ? esc_html('$' . number_format($value, 0, '.', ',')) : '-';
    									break;
    							default:
    									echo '-';
    									break;
    					}
    			}

    And here is the solution (which is to use get_post_meta with the proper field name of having the group field name precede the sub field name. Here is the updated code that worked for me:

    			// Display the value of the custom fields in the custom columns
    			public function display_custom_column_content($column_name, $post_id) {
    
    					switch ($column_name) {
    							case 'bedrooms':
    									$value = get_post_meta($post_id, 'general_info_bedrooms', true);;
    									echo $value ? esc_html($value) : '-';
    									break;
    							case 'bathrooms':
    									$value = get_post_meta($post_id, 'general_info_bathrooms', true);;
    									echo $value ? esc_html($value) : '-';
    									break;
    							case 'size':
    									$value = get_post_meta($post_id, 'general_info_size', true);
    									echo $value ? esc_html(number_format($value) . ' sq. ft.') : '-';
    									break;
    							case 'lot_size':
    									$value = get_post_meta($post_id, 'general_info_lot_size', true);
    									echo $value ? esc_html(number_format($value) . ' sq. ft.') : '-';
    									break;
    							case 'price':
    									$value = get_post_meta($post_id, 'general_info_price', true);
    									echo $value ? esc_html('$' . number_format($value, 0, '.', ',')) : '-';
    									break;
    							default:
    									echo '-';
    									break;
    					}
    			}
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.