Support

Account

Home Forums General Issues Readout all values of a certain field Reply To: Readout all values of a certain field

  • This went faster than I thought. I basically had to copy/paste those codes you linked to.

    Here’s what I did:

    function get_custom_values( $key = 'YOUR_FIELD', $type = 'post', $status = 'publish' ) {
    
    		    global $wpdb;
    
    		    if( empty( $key ) )
    		        return;
    
    		    $custom_arry = $wpdb->get_col( $wpdb->prepare( "
    		        SELECT pm.meta_value FROM {$wpdb->postmeta} pm
    		        LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
    		        WHERE pm.meta_key = '%s' 
    		        AND p.post_status = '%s' 
    		        AND p.post_type = '%s'
    		    ", $key, $status, $type ) );
    
    		    foreach ($custom_arry as $custom_field) {
    		    	$custom_result.= $custom_field. "SEPARATION_SIGN";
    			}
    
    			return $custom_result;
    		}
    
    		$fina_custom_result = get_custom_values();