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();
Thank you!
It seems like things are gonna get a lot harder for me 🙂
I gonna try this out and if I get it to work, I’ll leave it here how I’ve done it.
Best,
Jordy
Hey James,
Thanks for your fast reply! Really appreciate it.
I was able to pass the post_id, but that just gives me one result.
I would like to fetch the values of all post_id’s from my custom field and put them into an array. Normally you do that with a for each, but loops don’t seem to work within the functions.php.
Best,
Jordy