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();
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.