Ok, ok, in classic form you know how after a couple of hours of banging your head and then posting in support as a final cry for help you stumble across the obvious answer.
Well, here it is in case anyone else is lost.
You need to make sure “SUB” is added to the code like so:
<?php if( get_sub_field('file') ): ?>
<a href="<?php the_sub_field('file'); ?>" >Download File</a>
<?php endif; ?>
So add “get_sub_field” and “the_sub_field” and it will work. You need to add “sub” for repeaters and adjust the code inside accordingly.
In your first example you are using the category__in argument which can only be used with the category taxonomy.
In WooCommerce the product category taxonomy is a custom taxonomy. Since it is a custom taxonomy instead of using category__in in your second example you should use a tax_query. Take a look at the tax_query documentation for wp_query, it is pretty intuitive to set up if you are not familiar with it.
Hope this is helpful!
Since you are using global $post one thing that occurred to me is if there are any custom queries on the page make sure that wp_reset_postdata() is called. It could be that somewhere in your template the global $post variable is being reassigned without being reset.
Not sure if this is relevant but hope this is helpful!
Hey @kandb,
Yeh – so it’s specifically that double wrapper that’s our main issue at the moment. We don’t get much control on the outer wrapper, that’s a WordPress default and our attempts to avoid applying those classes/styles there have caused issues. The inner “wrapper” comes from your template, and that’s where these styles should live – but because we need to render PHP to build your template, we can’t easily “live” update your template with the styles as you do something in the block editor, say adding padding etc.
Also, of course – someone could decide to put the styles somewhere deeper into the DOM of their template, so we can’t also just rely on the “outer” wrapper being the place where that should live. If we do stop the styles being applied on the WordPress outer wrapper, you’d have to wait for the AJAX request to re-render the template to see your changes, and this feels incredibly slow and “broken” vs native blocks.
Anyway! We’ll get the fix for specific issue of the editor “forgetting” when you’ve applied things like spacing in the next day or so, and figure out the way forward from there!
Hi,
I also have the same problem with images in ACF blocks. Width & height restrictions from ACF image fields are being applied to the Core image block, if I add a core image block to the page after the ACF block.
If I:
I have tested this quite a bit:
I have been unable to solve this.
Environment:
Hmm.. the same problem here and only for one specific site. @buddyq Did you solve the problem?
I had a similar issue where i needed to add the ACF fields meta_id. Below is my solution to the same problem
function build_meta_key($field){
// Loop over parents.
$return_name = $field["_name"];
if(empty($field["prefix"])){
return $return_name;
}
$is_row = preg_match("/row-(\d)+/", $field["prefix"], $matches);
if(!$is_row){
return $return_name;
}
//now figure out the row number from the field name
$return_name = $matches[1]."_".$return_name;
while ( $field['parent'] && $field = acf_get_field( $field['parent'] ) ) {
if(isset($field["_name"])){
$return_name = $field["_name"]."_".$return_name;
}
}
return $return_name;
}
function get_all_meta_info_by_key($post_id, $meta_key, $meta_type = "post"){
global $wpdb;
if ( ! $meta_type || ! $post_id || trim($meta_key) == "") {
return false;
}
$table = _get_meta_table( $meta_type );
if ( ! $table ) {
return false;
}
$meta = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$table} WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key) );
if ( empty( $meta ) ) {
return false;
}
if ( isset( $meta->meta_value ) ) {
$meta->meta_value = maybe_unserialize( $meta->meta_value );
}
return $meta;
}
/**
* Add in the ACF fields meta id to the field itself. so we can build the download links
* @param $field
*
* @return mixed
*/
function prepare_field( $field ) {
global $post;
$acf_meta_key = $this->build_meta_key($field);
$meta_information = $this->get_all_meta_info_by_key($post->ID, $acf_meta_key);
if(!empty($meta_information->meta_id)){
$field["post_meta_id"] = $meta_information->meta_id;
}
return $field;
}
Hey ACF/Elementor Friends đ
Here are some snippets that are working on my client’s site:
PHONE MAILTO
// Convert Mobile to tel link
add_filter('acf/format_value/name=ACF_MOBILE_FIELD_NAME', 'convert_phone_to_link', 20, 3);
function convert_phone_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$tel_link = preg_replace('/[^0-9]/', '', $value);
$value = '<a href="tel:'.$tel_link.'">'.$value.'</a>';
return $value;
}
EMAIL MAILTO
// Convert Email to mailto link
add_filter('acf/format_value/name=ACF_EMAIL_FIELD_NAME', 'convert_email_to_link', 20, 3);
function convert_email_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$email_link = $value;
$value = '<a href="mailto:'. $email_link .'">'. $value .'</a>';
return $value;
}
Done!
I’m sort of “wait and see” on the ownership change, but I can certainly see the advantages of having more resources available. I’ve seen some neat feature requests not happen probably more due to limited time/talent than anything else.
Would like to see them hire you, John, if that’s ever an option. đ
Ok, I don’t know why, but it’s working as expected now.
It must have been a cache issue, but I swear I was clearing the cache regularly.
For the sake of closure, here’s the code that worked (once the field was accessible):
<section class="center-align stories" id="stories">
<div class="wrap cf">
<div class="row">
<?php
if (have_posts()) : while (have_posts()) : the_post();
$my_id = get_the_ID();
?>
<?php // Only show posts where 'visibile_on_index' is not 0 (either 1 or unset)
if (get_post_field('visible_on_index', $my_id) != 0) { ?>
<div class="fourth <?php foreach(get_the_category() as $cat){ echo ' '.$cat->slug; }?>">
<div class="inner">
<a href="<?php the_permalink(); ?>" class="img-holder" style="background-image: url(<?php the_post_thumbnail_url('full'); ?>)"></a>
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
<?php the_excerpt(); ?>
</div>
</div>
<?php }; ?>
<?php endwhile; ?>
<?php bones_page_navi(); ?>
<?php endif; ?>
</div>
</div>
</section>
Have you added the field afterwards?
No, field was added before I started trying to use it on the archive page.
Have you re-saved the posts then?
Yes, I can see the field on the Admin side when I edit a post (and on the index view since I’m also using the ACF QuickEdit fields plugin).
Are the other fields coming from a different field group or are they in the same group?
They are in a different group. I tried creating the field in a group that *does* appear using get_fields()
, but no change. I checked settings between this group (that doesn’t appear) and a group that does appear and all settings are the same.
In ACF Pro v5.9 or more, you can do :
function your_function_name($field) {
return false;
}
add_filter("acf/prepare_field/name=my_acf_field", "your_function_name");
Iâm not quite understanding the problem here. First you say:
If I call the field in the custom section I get a result (15), so I know the field has a value.
And then you say:
I can give the shortcode a parameter for ID, but in that custom section, I canât get the actual ID to put it in the shortcode.
Also, what do you get if you do var_dump($id_i_need)
?
You can change field labels but not field names (slugs) without losing the connection to previously entered data.
For example, if you have a text field with label âCamera Lens 1â and field name âcamera_lens_1â you can change the label and the new label text will be shown in the templates where this label is used. But if you change the field name it will not update the old data in the database, so you would start with an empty list again. The old data isnât lost, itâs still in the database, but it wonât be accessible unless you change the name back to the old one.
I hope Iâve understood your question correctly. For more specific answers youâll have to post your field setup exactly.
Thanks for reply.
but it looks doesn’t work. even i hard code the post id.
<?php echo get_field('students_no_class', get_queried_object() , 456 ) ?>
The layout name is not part of the meta key, I’m not sure about your code but it might be
$column_module = get_post_meta( $post_id, 'section_layout_'.$count.'_single_col_elements_content_type', true );
A nested flex field, or fields would be something like
"{$flex_field_name}_{$index}_{$nested_flex_name}_{$index}_{$sub_field_name}"
I have an example of doing this here https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/unique-repeater-checkbox
Yes, if you want to get fields from a category and not the post then you must supply the category ID in the form of "term_{$term_id}"
or you can supply the term object as in your first code example.
You can get the terms of the post using get_the_terms()
This question ranks highly in the search engine, so I would like to share a method how resolve field groups being stuck on “Awaiting Save”.
/acf-json
folder.How I think it happened
At first, I told ACF to save JSON to a theme subfolder: get_stylesheet_directory() . /acf-json
. Next, I added two new field groups and saved them. However, later on I changed my mind, and added a second, conflicting PHP file, which told ACF to save local JSON to /mu-plugins/acf-json
. However, I forgot to create the /mu-plugins/acf-json
folder, which meant I was telling ACF to write JSON somewhere non-writable: a directory which didn’t exist.
A couple weeks pass before I get to work this project again. I had not though much about the local JSON, until I was ready to commit the finished field group. However, I noticed that updates to the field groups were no longer showing in the version control panel in Visual Studio Code. After digging around in the theme and the mu-plugins folder, I deleted the second, conflicting PHP file. Nevertheless, even after removing the reference to the non-existent folder, ACF was not able to save local JSON to the theme. All field groups, even brand-new ones, were stuck at “Awaiting Save”. It seemed like the only way to save the field groups would be to start over: export to JSON, delete all, then import from JSON.
Same problem here. Didn’t find a filter or anything to avoid escaping HTML inside Select2 fields. But there’s another thread with an answer from a developer:
https://support.advancedcustomfields.com/forums/topic/wp_kses-breaks-select-images/
This is my code
// Target form and add row
function set_structure_note( $entry, $form ) {
$structure_note = rgar( $entry, â1â );
$note_user = rgar( $entry, â4â );
$row = array(
âstructure_noteâ => $structure_note,
âstructure_authorâ => $note_user,
);
add_row(âstructure_notesâ, $row);
};
My <p style=”font-size:1px”>pintodown </p>
downloader site also works with the same pattern as yours
Hello I am trying to limit the gallery show only 2 images. But it doesn’t seem to work. Any idea what am I doing it wrong here?
Thanks
<?php
// if ACF is not active, abort.
if ( ! class_exists( 'acf' ) ) {
return;
}
$images = get_field( 'main_product_gallery' );
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if ( $images ) {
$counter = 1;
?>
<div class="product-gallery">
<?php
foreach( $images as $image ) {
?>
<div class="product-gallery__image-wrap ratio-1-1">
<?php echo wp_get_attachment_image( $image['ID'], $size );?>
</div>
<?php
$counter++;
if ($couner == 2) {
break;
}
}
?>
</div>
<?php
}
?>
Yep – changing it to get_field("news_source",$recent["ID"])
did the trick and now it’s returning the appropriate content. Thanks!
Hey aloeroot,
I’m guessing you could create a new page template to pull all the posts that feature the ACF fields you’re looking for. This is how I would do it:
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'spanish_strip', // or any other language
'value' => '"'. get_the_ID() .'"',
'compare' => 'LIKE',
)
)
);
$spanish_strips = get_posts($args);
echo '<h1>Archive for Spanish Comic Strips:</h1>';
foreach ($spanish_strips as $strip) : ?>
<!-- You do something nice here :) -->
<?php endforeach;
Note that the get_posts()
function only retrieves the last 5 entries, so either add 'numberposts' => -1
to the arguments or use a standard WP_Query.
Hope this helps!
My solution:
<?php echo str_replace('<p>', '<p class="yourclass">', get_field( 'yourfield' ) ); ?>
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.