Hi,
I’m trying to retreive repeter subfields values using DB queries and get_field_object() for a client of mine who wants to keep fields contents as raw content in post_content.
My repeter field is jst_iconbox and my subfield is iconbox_content.
I’ve created 3 iconbox fields on admin page and i’m quering the DB like this :
global $wpdb;
$prefix =$wpdb->prefix;
$tablename = $prefix."postmeta";
$sql = "SELECT * FROM {$tablename} WHERE meta_key LIKE %s GROUP BY meta_key";
$iconbox_contents = $wpdb->get_results( $wpdb->prepare( $sql, '_jst_iconbox_%_iconbox_content' ) );
But while i’m looping through my result i have no value foreach field found :
foreach( $iconbox_contents as $boxcontent )
{
$field = get_field_object( $boxcontent->meta_value, get_the_ID() );
echo '<pre>'.print_r( $field, 1) .'</pre><hr>';
}
… prints 3 times somting like :
[ID] => 1825
[key] => field_59d4a5496ec7d
[label] => JsT Iconbox Content
[name] => jst_iconbox_content
[prefix] => acf
[type] => wysiwyg
[value] =>
[menu_order] => 0
I must have missanderstood something …
Any idea ?
Thank’s
If I understand your query correctly then you should probably be using $boxcontent->meta_key
where you have $boxcontent->meta_value
Thank’s for answering.
Hell Yes ! It sounds obvious but this does not retreive anything (empty result) …
This is the full code :
global $wpdb;
$prefix =$wpdb->prefix;
$tablename = $prefix."postmeta";
$sql = "SELECT * FROM {$tablename} WHERE meta_key LIKE %s GROUP BY meta_key";
$iconbox_contents = $wpdb->get_results( $wpdb->prepare( $sql, '_jst_iconbox_%_iconbox_content' ) );
if( $iconbox_contents )
{
foreach( $iconbox_contents as $boxcontent )
{
$field = get_field_object( $boxcontent->meta_key, get_the_ID() );
echo '<pre>'.print_r( $field, 1) .'</pre><hr>';//now this is empty
}
}
Still stuck with this…
It’s probably because of the way that the repeater fields work and you’re probably not going to be able to use the ACF functions in this case.
You already have the value of the field, you’ve just got to run the filters on it, assuming that these are wysiwig fields:
echo apply_filters('acf_the_content', $boxcontent->meta_value);