Not sure what you are referring to.
a field is a post type. Most of the settings for the field are stored in post_content. Some field settings are stored in post meta.
For the actual field, there is one entry that is "_{$feild['name']}"
that contains the field key of the field that is associated with $field['name']
and this is where you will find the content for the field.
Unless we’re talking about guberbuggutenberg. In this case I believe that all of the content is actually stored in post_content for the post.
Revisiting this topic, as I’m working on another project where I have to find specific data in ACF fields.
So I have a wysiwyg field with a key named field_59c990d0410b8. When using phpmyadmin, all I can find is one record for the settings for that field, not the actual content.
Is the content stored somewhere else? In post_content perhaps?
Are there any guides for doing searches on content entered into ACF? I couldn’t find anything, just lots of highly specific questions. So might be helpful to have a guide explaining this, since ACF content is not searchable using wordpress itself.
@edwinsnotje very nice start, I wanted to add this to a current project as soon as I saw your reply. Try this:
.acf-image-uploader.has-value .hide-if-value {
display: block;
clear: both;
float: left;
margin: 1em 0;
}
.acf-image-uploader.has-value .hide-if-value p {
visibility: hidden;
}
.acf-image-uploader.has-value .hide-if-value p a {
visibility: visible;
float: left;
color: transparent;
padding-right: 2.5em;
}
.acf-image-uploader.has-value .hide-if-value p a:before {
visibility: visible;
content: "Change Image";
position: absolute;
color: #0071a1;
}
I had the same issue with a client who didn’t think of deleting the image in order to select a new one (or to upload a new one). I solved it by preventing ACF to hide the ‘Add new image’ button that is visible when no image is selected yet. If you have an admin.css stylesheet just add this:
.acf-image-uploader.has-value .hide-if-value {
display: block;
clear: both;
float: left;
margin: 1em 0;
}
It’s the first directive that does the trick, the rest is for some proper formatting of the button when there is an image present.
If there isn’t an admin stylesheet you just enqueue one with this rule.
The button remains visible when there is already an image, so you can use it to select a new one. It works for replacing.
I changed .po file accordingly to reflect this possibility: change ‘Add image’ to something like ‘Select image’ so it’s more generic.
Found this related question (after relentlessly changing search parameters):
https://support.advancedcustomfields.com/forums/topic/multisite-location-rules-display-field-groups-on-specific-sites/ and got my answer in the question, didn’t even know rule matching filters existed!
My sites live on subdomains, so I preferred to change the display list to use the blog (site) name rather than either their subdomain or path (mine were all “/”), so in the acf_location_rule_values_multisites
function, I changed the the loop to show names instead.
foreach( $sites as $site ) {
$name = get_blog_details( array( 'blog_id' => $site->blog_id ) )->blogname;
$choices[ get_object_vars($site)["blog_id"] ] = $name;
}
Note I put this function in the parent theme, child theme alone would’ve prevented it showing on other satellite sites not using the same child theme.
I’m still choosing to make the field groups on each satellite site, though they are appearing available to sync on all the other satellite sites, though I can either just hit sync and have them all in (which shouldn’t matter since they’ll only show on the correct site anyway) or ignore them when syncing everything else to keep it clean).
Can’t find where to delete but solved this one on my own. Thanks 🙂
// This populates and saves search terms for product landing pages based on what lives in the product tables
function save_search_terms( $post_id ) {
$searchterms = array();
if( have_rows('product_table') ):
while( have_rows('product_table') ) : the_row();
// Loop over sub repeater rows
if( have_rows('product_table_products') ):
while( have_rows('product_table_products') ) : the_row();
// Get sub value
foreach( $tempsearchterms as $tempsearchterm );
$tempsearchterm = get_sub_field('product_table_product');
$searchterms[] = $tempsearchterm->part_number . " " . $tempsearchterm->product_name . " " . $tempsearchterm->model_type;
endwhile;
endif;
endwhile;
endif;
// update field
update_field('search_terms', $searchterms);
}
add_action('acf/save_post', 'save_search_terms');
Okay so you should use the following:
<?php
$download = get_field('download');
if( $download ): ?>
<a class="button" href="<?php echo esc_url( $download ); ?>">Download File</a>
<?php endif; ?>
This would go in the php template file with the other content for the page you wish to add it to.
Okey @hube2 (John Huebner)
thanks for the quick revert .. Now I am going to try. Hope it will work for me … 🙂
It seems that the format I used for $argsar needs to be changed to
$argsar = array (
'post_type' => 'auctionroom',
'meta_query' => array(
array(
'key' => 'auctionroom_username',
'compare' => '=',
'value' => $auctionroomname
)
)
);
Hope it helps someone
OK Found it.
As per the Code reference, the function uses four values:
wp_get_attachment_image( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false, string|array $attr = '' )
Where I use only three. If I add the fourth value like so:
echo wp_get_attachment_image($image, $size, "",array('class' => 'rounded-top') );
It works. So problem solved.
What makes it hard to spot the fault is that WP seems to use four values where in this case the four values seem required?
Anyway, thanks for looking into this and pointing me toward the code reference.
Hi John,
Question: is the class populated with anything?
I use the class in other places on the site if that is what you mean?
Possibly there is a filter on ‘wp_get_attachment_image_attributes
mmhh, I looked for something like that but could not find anything. Are you saying the code is correct and should work?
I use <?php the_post_thumbnail('large', array('class' => 'rounded-top')); ?>
in other places on the site and that works. My rounded-top class is added to the wp-post-image class.
I tried using
$image = get_field('card1_image');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size, array ('class' => 'rounded-top' ) );
}
In twenty-ten and it does not work either. The only classes I see is attachment-full size-full
In the ACF field settings I use the “ID” since I want the srcset thing.
Thanks
Migration – as usual – export db into file, change all occurrences of old domain to new one. Everything else works fine without problem. I have lot’s of experience in WP.
It’s not the first time I’m doing this, that’s also why I’m bit confused.
Two years ago I migrated the same WP instance from same development server, to almost same live server. Difference between those two live servers is in MySQL – on first (where it works, installation two years ago) is 5.6.49 and on second (where I have a problem) is 5.0.12.
But, all in all, it looks like those ACF variables are not “registered” or something like that… looks like they are not “visible” or accessible on front end. Can I help myself by adding something in functions.php file or something like that?
Thank you in advance!
A littel more details on whats happening. I’ve got a woocomemrce shop setup and ACF_Form to show up on each individual order page on the front and back end through ACF_FORM. Person purchases product and then has to fill out the required information on the order to finish and submit.
After the information is full we don’t want it to be edited without contacting customer support. the call to the product and form is simple as follows
<?php if ($product_id == 263 ) :
acf_form(array(
'post_id' => $order_id,
'field_groups' => array( 382 ),
'post_title' => false,
'post_content' => false,
'submit_value' => __('Update Info')
));
endif; ?>
Workin great, just don’t understand if I can run a check on the exisiting ACF_form data to see if it’s empty. Is looping through each field first the key and then showing the form if one comes back say empty/false?
Are you meaning for your end user to download a file? If you use URL as the field type, it will take you to the url. By using the File field type, you can select ‘File URL’ as the return value and then on the php page use:
<?php
$file = get_field('download');
if( $file ): ?>
<a href="<?php echo $file['url']; ?>"><?php echo $file['filename']; ?></a>
<?php endif; ?>
to grab the value on the front end. Then when the link is clicked, the download will be done automatically.
Looking at your code and the code for the WP function I only see one thing that could be causing this.
https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
Question: is the class populated with anything?
Possibly there is a filter on ‘wp_get_attachment_image_attributes’
$queried_object = get_queried_object();
the_field('lorem_ipsum', $queried_object)
It’s possible in a simple way now. You can only create an ACF empty block with an InnerBlock included, and all options in this block (eg Button Group) will be visible in the sidebar.
As a result, we get something like “gutenberg block options”
The problem I am seeing is performance. If you have a lot of inner blocks, you have a lot of Ajax queries. As a result, loading this in wp-admin is slow.
You did it in a smart way. I like this.
Of course, now that Gutenberg is released we can achieve it in several ways.
If we are talking about ACF only, it’s also possible in a simple way now! You can only create an ACF empty block with an InnerBlock included, and all options in this block (eg Button Group) will be visible in the sidebar.
As a result, we get something like “gutenberg block options”
The problem I am seeing is performance. If you have a lot of inner blocks like container
> row
> col
> content
, you have a lot of Ajax queries. As a result, loading this in wp-admin is slow.
Because in functions.php, before the loop, ACF does not know what post to get the value from. Missed that earlier.
You need to supply ACF with the post ID. This needs to happen inside “the loop” or you need to figure out the post ID that will be loaded, if it is a single post.
for example
$queried_object = get_queried_object();
if (is_a($queried_object, 'WP_Post')) {
if (get_field('', $queried_object->ID)) {
....
}
}
Even using this it may not work until after ‘init’ and you should never call an acf function before ‘acf/init’ the reason for this is that it causes premature initialization of ACF that can cause other issues. I would suggest trying to to this on and the WP ‘init’ action with a high priority.
Hello,
I increased the quotas of max_input_vars, max_input_nesting_level and post_max_size but the problem persists.
is there another probable source of the problem?
Thank you,
Hello,
I increased the quotas of the max_input_vars, max_input_nesting_level and post_max_size, but the problem persists.
is there another probable source of the problem?
Thank you,
Well, still not sure why any of the code examples in the ACF forums like this post Expire post to draft or this post Expire Posts on Datepicker field
aren’t working.
Here’s what finally worked for me:
Publish based on datepicker field “publish_coupon_date”
add_action( 'wp', 'publish_coupons_daily' );
function publish_coupons_daily() {
if ( ! wp_next_scheduled( 'publish_coupons' ) ) {
wp_schedule_event( strtotime('07:02:00'), 'daily', 'publish_coupons');//runs at or after 12:02am local time, server time is in UTC
}
}
add_action( 'publish_coupons', 'publish_coupons_function' );
function publish_coupons_function() {
$date_default_timezone_set('America/Los_Angeles'); // ensures the comparison happens based on local timezone, not on server UTC time, so they don't get published too soon
$today = date('Ymd');
$args = array(
'post_type' => array('coupon'), // post types you want to check
'post_status' => 'draft',
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$publishdate = get_field('publish_coupon_date', $p->ID, false, false); // get the raw date from the db. false, false will convert to Ymd while allowing you to use any date format output choice on the field
if (($publishdate > $today) || ($publishdate = $today)) {
//if date is today OR prior to today
$postdata = array(
'ID' => $p->ID,
'post_status' => 'publish'
);
wp_update_post($postdata);
}
}
}
and expiring posts from datepicker field “expire_coupon_date”
add_action( 'wp', 'expire_events_daily' );
function expire_events_daily() {
if ( ! wp_next_scheduled( 'delete_expired_events' ) ) {
wp_schedule_event( strtotime('07:01:00'), 'daily', 'delete_expired_events'); //runs at or after 12:01am local time, server time is in UTC
}
}
add_action( 'delete_expired_events', 'expire_coupon_function' );
function expire_coupon_function() {
date_default_timezone_set('America/Los_Angeles'); // see other note, we set this to ensure it expires on local time, not server time
$today = date('Ymd');
$args = array(
'post_type' => array('coupon'),
'post_status' => 'publish',
'posts_per_page' => -1
);
$posts = get_posts($args);
foreach($posts as $p){
$expiredate = get_field('expire_coupon_date', $p->ID, false, false); // get the raw date from the db. false, false will convert to Ymd while allowing you to use any date format output choice on the field itself
if (($expiredate < $today) && ($expiredate != "")) { // if date is less than today, but also not empty to accomodate the coupons that don't expire
$postdata = array(
'ID' => $p->ID,
'post_status' => 'draft'
);
wp_update_post($postdata);
}
}
}
have fun kiddies.
in my template page I have this loop:
<div class="row">
<?php
if(have_rows('mb_collection_strates')):
while(have_rows('mb_collection_strates')): the_row();
$layout = get_row_layout();
echo clrz_get_template_part('collections-level-one', $layout);
endwhile;
endif;
?>
</div>
which uses files one of them contains this code
<div class="strate-collection-hairstyle strate-collection-hairstyle--mobile margin-bottom-xl">
<div class="container-fluid">
<div class="row collection-hairstyle-container js-hairstyle-tabs tabs">
<div class="col-xs-12 col-xs-offset-2 js-tab-content">
<div class="row">
<?php
$i = 0;
$tabsRepeater = get_sub_field('mb_hairstyle_tabs_repeater');
$tabsList = '<div class="col-xs-12 col-xs-offset-2 tabs__list"><ul class="text-uppercase js-tabs">';
if ( have_rows('mb_hairstyle_tabs_repeater') ) :
while ( have_rows('mb_hairstyle_tabs_repeater') ) : the_row();
$i++;
$tabName = get_sub_field('mb_tab_name');
$tabTitle = get_sub_field('mb_tab_title');
$tabText = get_sub_field('mb_tab_text');
$tabImg = get_sub_field('mb_tab_illustration');
$tabBtnLabel = get_sub_field('mb_tab_button_label');
$tabBtnExternalTarget = get_sub_field('mb_tab_external_target');
$tabBtnUrl = get_sub_field('mb_tab_button_target_url');
// $tabInternalLink = get_sub_field('mb_tab_internal_link');
if ( $tabBtnExternalTarget ) :
$link = get_sub_field('mb_tab_button_target_url');
else:
$link = get_sub_field('mb_tab_internal_link');
endif;
// Récupération infos meta de la page cible (image pour Pinterest)
$subPageId = url_to_postid($link);
$seoOgDescription = $tabTitle . ' - ' . $tabText;
// priorité à l'image SEO Yoast
$seoOgImageUrl = get_post_meta($subPageId, "_yoast_wpseo_opengraph-image")[0];
if (!$seoOgImageUrl) { // Fall-back sur l'image de l'onglet
$seoOgImageUrl = clrz_get_image_url($tabImg, '625x880');
}
// TESTS
// var_dump(get_post_meta($subPageId));
// echo '<img src="' . $seoOgImageUrl . '" alt="bob" />';
// END TESTS
if ( $i == 1 ) :
$active = 'active';
else:
$active = '';
endif;
$tabsList .= '<li class="tabs__name text-uppercase js-tab js-tab-content '. $active .'" data-id="' . $i . '">' . $tabName . '</li>';
?>
<div class="col-xs-16 margin-bottom-md tabs__content js-tab-content <?php echo $active; ?>" data-id="<?php echo $i;?>">
<img />" alt="">
</div>
<div class="col-xs-16 tabs__content black js-tab-content <?php echo $active; ?>" data-id="<?php echo $i;?>">
<div class="content">
<div class="title-sub">
<p class="h2 black smooth-font"><?php echo $tabTitle ?></p>
</div>
<p class="tabs__content--text"><?php echo $tabText?></p>
<div class="tabs__content--footer clearfix">
<?php if ($tabBtnLabel) : ?>
<a>" class="text-uppercase button button--black" title="<?php echo $tabBtnLabel?>"><?php echo $tabBtnLabel?></a>
<?php endif; ?>
<ul class="socials margin-top-md">
<li class="button">
<a>" target="_blank" title="<?php echo __( 'Partager sur Facebook', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-facebook"></use>
</svg>
</a>
</li>
<li class="button">
<a>&media=<?php echo urlencode($seoOgImageUrl); ?>&description=<?php echo urlencode(strip_tags($seoOgDescription));?>" target="_blank" title="<?php echo __( 'Partager sur Pinterest', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-pinterest"></use>
</svg>
</a>
</li>
<li class="button">
<a>&text=<?php echo urlencode(strip_tags($seoOgDescription));?>" target="_blank" title="<?php echo __( 'Partager sur Twitter', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-twitter"></use>
</svg>
</a>
</li>
</ul>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
</div>
</div>
<?php
$tabsList .= '</ul></div>';
echo $tabsList;
?>
<!-- PRODUITS RELATIFS A L'ONGLET -->
<?php
if ( have_rows('mb_hairstyle_tabs_repeater') ) :
$i = 0;
$j = 0;
while ( have_rows('mb_hairstyle_tabs_repeater') ) : the_row();
$i++;
if (have_rows('mb_tab_products')) :
while ( have_rows('mb_tab_products') ) : the_row();
?>
<?php
// $hairstyleTitle = get_sub_field('mb_hairstyle_title');
// $hairstyleText = get_sub_field('mb_hairstyle_text');
// $hairstyleImg = get_sub_field('mb_hairstyle_illustration');
// var_dump(get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_0_mb_hairstyle_title'));
// $productTitle = get_sub_field('mb_product_title');
// $productText = get_sub_field('mb_product_text');
// $productImg = get_sub_field('mb_product_illustration');
// $productBtnLabel = get_sub_field('mb_product_button_label');
// $productExternalBtn = get_sub_field('mb_product_external_link');
$hairstyleTitle = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_title');
$hairstyleText = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_text');
$hairstyleImg = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_illustration');
$productTitle = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_title');
$productText = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_text');
$productImg = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_illustration');
$productBtnLabel = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_button_label');
$productExternalBtn = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_external_link');
$productImgSize = 'full';
$position = get_sub_field('mb_hairstyle_product_position');
$j++;
if ( $productExternalBtn ) :
$link = get_sub_field('mb_product_button_target_url');
else:
$link = get_sub_field('mb_product_internal_target');
endif;
if ($position == 'left') :
$class = '';
$content = 'col-xs-12 col-xs-offset-2';
$positionClass = 'strate-collection-product--left';
else:
$class = 'pull-right';
$content = '';
$positionClass = 'strate-collection-product--right';
endif;
if ($i == 1) :
$positionClass .= ' active';
endif;
?>
<div class="col-xs-16 strate-collection-product <?php echo $positionClass; ?> js-tab-content" data-id="<?php echo $i?>">
<div class="row">
<div class="col-xs-14 col-xs-offset-right-2 bg-black collection-product__hairstyle <?php echo $class; ?>">
<div class="row">
<div class="content <?php echo $content; ?> margin-top-xl">
<div class="title-sub margin-bottom-sm">
<span class="h2 white smooth-font"><?php echo $hairstyleTitle ?></span>
</div>
<p class="smooth-font white"><?php echo $hairstyleText;?></p>
</div>
<img />" alt="">
<ul class="socials <?php echo $content; ?> margin-bottom-md">
<li class="button">
<a>" target="_blank" title="<?php echo __( 'Partager sur Facebook', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-facebook"></use>
</svg>
</a>
</li>
<li class="button">
<a>&media=<?php echo urlencode(clrz_get_image_url($productImg, $productImgSize)); ?>&description=<?php echo $productTitle;?>" target="_blank" title="<?php echo __( 'Partager sur Pinterest', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-pinterest"></use>
</svg>
</a>
</li>
<li class="button">
<a>&text=<?php echo $productTitle;?>" target="_blank" title="<?php echo __( 'Partager sur Twitter', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-twitter"></use>
</svg>
</a>
</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-xs-offset-2 collection-product__product">
<?php if($productTitle == ""):?>
<?php /* nothing to do */ ?>
<?php else: ?>
<span class="h2 text-uppercase margin-bottom-lg"><?php echo $productTitle; ?></span>
<?php endif;?>
<div class="text-center">
<div class="margin-bottom-md h-auto row">
<img />" alt="">
</div>
<p class="margin-bottom-md wysiwyg"><?php echo $productText?></p>
<?php if($productBtnLabel == ""):?>
<?php /* nothing to do */ ?>
<?php else: ?>
<a>" class="text-uppercase button button--black" title="<?php echo $productBtnLabel;?>"><?php echo $productBtnLabel;?></a>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
endif;
endwhile;
endif;
?>
</div>
</div>
</div>
When I modify the value of one of it’s field, and after modifying the page I still find the old value, also when create a new field and I try to fill it it always remains empty.
John, again you’re a life safer.
Apparently I was searching in the wrong direction.
Many many tnx.
All kuddos go to you:
https://stackoverflow.com/questions/64222453/get-acf-field-values-of-related-group-via-post-object-in-functions-php/64246663#64246663
You cannot get sub fields of the first repeater inside of the nested repeater loop.
if (have_rows('repeater')) {
while (have_rows('repeater')) {
// you can access sub fields of "repeater" here
if (have_rows('nested_repeater) {
while (have_rows('nested_repeater) {
// you can access sub fields of nested repeater here
// you cannot access sub fields of "repeater" here
} // end while nested repeater
} // end if nested repeater
// you can access sub fields of "repeater" here
} // end while "repeater"
} // end if "repeater"
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.