Not only would you need to hide the tab but you would also need to filter and hide all of the fields in that tab.
You do not want to unset the field, you need to return false
// Apply to fields named "example_field".
add_filter('acf/prepare_field/key=field_60647c32d82ce', 'hide_ani_tab');
function hide_ani_tab($field) {
if ( false == get_field( 'animation_option', 'option' ) ) {
// remove tab by field key
return false;
}
return $field;
}
but as I said, this would need to be done for the tab and all of the fields in the tab
These solutions all require you to manually bump the version number in your composer.json
every time there’s a release. If you manage more than one or two sites, this is a huge pain.
Created this as a general-purpose alternative. Can be set up for ACF and should work for a variety of other private plugins/themes.
Sorry to resurrect an old thread, but I’ve just been pulling my hair with the same issue on a new project.
It was proving very difficult to get fields and sub fields to match references, as I needed them to, for various template parts.
In my example,the client had a broad colour palette,and pretty much every page component (built using flexible content) could use any colour from the palette.
Rather than manually recreate the colour select field,I thought I’d be a bit more efficient and create a select field in a ‘brand options’ field group,and then clone that field whenever needed. For example:
– Hero banner
– – Title
– – Image
– – Colour (clone field)
And
– Flexible Content
– – CTA Box
– – – Title
– – – Text content
– – – Colour (clone field)
In the hero banner, the data is obtained by get_field,the CTA Box by get_sub_field. The colour field for the subfield was a Lot harder to get to.
I think part of my problem is that I quite like using unique field names, which isn’t necessary for nested content, becausevi findit easier for debugging.
Update from SiteGround:
Object Caching works as designed to and it is up to the plugin devs to play nice with it. If they don’t know how to work with persistant object caching like Memcached or Redis I am afraid that there isn’t much we can do about it but to disable the caching or to switch to a better plugin than ACF Pro.
Using the acf pro gallery field:
<?php
$images = get_field('project_gallery');
if( $images ): ?>
<?php foreach( $images as $image ):
$data_type = pathinfo($image['url'], PATHINFO_EXTENSION);
if ($data_type == 'mp4') {?>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<video preload="metadata">
<source src="<?php echo $image['url'];?>#t=0.5" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<?php } else {?>
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
<a href="<?php echo esc_url($image['url']); ?>">
<img src="<?php echo esc_url($image['sizes']['large']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
</a>
</div>
<?php } endforeach; ?>
<?php endif; ?>
So here, you check if an “image” (whatever you get from the library), comes with an .mp4 extension. If it’s true, it means you used a video, and you create an html5 video element. Else, it’s just an image.
For those who need it, here is an example on how to create a gallery of external videos using the repeater field and as a sub_field the oEmbed field.
This code came from another thread of questions somewhere. I don’t remember where, so it’s not my code, I just made some changes to meet my needs.
<?php
// check if the repeater field has rows of data
if( have_rows('external_gallery_videos') ):
// loop through the rows of data
while ( have_rows('external_gallery_videos') ) : the_row();
// get the sub field value
$sub_value = get_sub_field('gallery_external_video');
// Use preg_match to find iframe src.
preg_match('/src="(.+?)"/', $sub_value, $matches);
$src = $matches[1];
// Add extra parameters to src and replcae HTML.
$params = array(
'controls' => 1,
'byline' => 0,
'portrait' => 0,
'title' => 0,
'hd' => 1,
'autohide' => 1,
'quality' => 'auto'
);
$new_src = add_query_arg($params, $src);
$sub_value = str_replace($src, $new_src, $sub_value);
// Add extra attributes to iframe HTML.
$attributes = 'frameborder="0"';
$sub_value = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $sub_value);
// Display customized HTML.
// echo $sub_value;
echo '<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"><div class="embed-container">'.$sub_value.'</div></div>';
endwhile;
else :
// no rows found
endif;
?>
Hi,
is there by now a way to only show one row of a repeater field?
My problem is this: I’m trying to build a math quiz for spam protection for a front end form.
So I’d need to select one random pair of question and answer from a repeater field in an options group, display the question field in the form and then validate the input value against the answer in the specific repeater row.
I had admittedly slightly misunderstood the request of this post, there is clearly a different between field layouts and specific fields.
Still, if you do want to find subfields of a field in a field group try..
SELECT *
FROM wpas_postmeta pm, wpas_posts p
WHERE pm.meta_value LIKE "%paragraph_with_large_image%"
AND pm.post_id = p.ID
AND p.post_status = "publish"
Just answering my own question in case someone needs this info:
According to this document listing acf code –
https://docs.wpdebuglog.com/plugin/advanced-custom-fields/5.8.8/function/acf_verify_nonce/
acf resets the nonce to “false” upon verification. So “false” as value for ‘acf_nonce’ in the $_POST actually means ‘verified’.
Sorry, I’m a bit of an ACF newbie so sorry if this is a silly question:
I’ve adapted the above code for my uses and tried adding it to my main .js file, but the function doesn’t appear to be firing. It seems that typeof acf
is undefined?
When you say “THIS BLOCK MUST COME BEFORE DOCUMENT READY, AFTER ACF JS HAS LOADED.”, where should it go? I wonder if this could maybe be the issue?
I have the same question! I don’t know how to change the front-end label “Zeeland Office:” to “Holland Office” on this page: http://www.lenzbalderins.com/
I changed the label from Zeeland to Holland but don’t see anywhere to effect the change on the front end?
Please help. Thank you.
John –
I have done some more testing here, and I can confirm that I see this problem behaviour with Relationship field and the Event Calendar tribe_events post type when the Polylang multilingual plugin is Enabled. I tried updating Polylang to latest version, and the problem still persists, so Polylang must be causing problems with the REST API query for post lookups in the Editor, I guess.
I’ll see if I can see any way of overcoming this in Polylang settings.
Thanks
Marcus
Hi John,
Thanks for your extended feedback and your vision on the makes and models part. Basically this is already implemented as is as the case described above within a single taxonomy in a parent child construction.
I managed to change the text for the tooltip and title from the popup thanks to your valuable feedback. Much appreciated, thanks!
So i have only 1 thing to figure out and that is altering that parent selector field for the taxonomy.
I have been digging true the fields file at “acf/includes/fields/class-acf-field-taxonomy”.
So basically i need to be able to modify/extend the class “acf_field_taxonomy” / function “ajax_add_term” and change the behavior for field key X and Y.
I will have some sleep and see if i can come to somekind of solution 😀
if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) {
$choices = array();
$response = $this->get_ajax_query($args);
if( $response ) {
foreach( $response['results'] as $v ) {
$choices[ $v['id'] ] = $v['text'];
}
}
acf_render_field_wrap(array(
'label' => __('Parent', 'acf'),
'name' => 'term_parent',
'type' => 'select',
'allow_null' => 1,
'ui' => 0,
'choices' => $choices
));
}
Thanks for looking at this
<?php get_field(‘morning_start_time’); ?>
Was throwing up an error, because of php within php maybe? Went with
<?php
date_default_timezone_set('Europe/London'); // timezone
$weekday = date(l); // today
$now = new DateTime();
$morning = $now >= new DateTime(get_field('morning_start_time','option')) && $now <= new DateTime(get_field('morning_end_time','option'));
$afternoon = $now >= new DateTime(get_field('evening_start_time','option')) && $now <= new DateTime(get_field('evening_end_time','option'));
if($weekday == "Saturday" && ($morning || $afternoon)) : ?>
<h2>We're streaming</h2>
<?php else : ?>
<h2>No streaming</h2>
<?php endif; ?>
It doesn’t throw up an error but its also not working. Would that be because of the php date/time functions? My return format is H:i currently
Or is there an easier way to make this work? I just can’t work this out
The solution proposed by John Huebner to Accept Only Unique Values is working fine in the backend.
But I made a frontend form using Elementor form and the error message of non unique value do not appear in the frontend form and also the post is saved in db even with duplicate value.
I am using Elementor Pro, ACF Pro and the ActionsPack plugin (Save action).
Does anyone knows a solution to this problem ?
Thnaks.
I just did a quick test on a test site I have running just ACF, Classic Editor and The Events Calendar on Twenty Seventeen. I tested all options. No post types selected for the field, multiple post types including events and only events. It worked in all cases.
It looks like you have some type of a conflict somewhere. Could be in another plugin or in the theme.
The only ACF specific things that I can think of would be a filter on acf/get_post_types
or possibly acf/fields/relationship/query
As far as the popup goes, I can’t really help you. The modal foe adding a term is the modal built into WP. I have never found any information on how to change this.
You could, in a round-a-bout way, alter the tooltip.
That being said, if I needed to build something like this for a client I would not be using a single taxonomy for make and model. Please bare with me because this is only where I would start and the details of getting it done would need to be figured out.
First I would use two taxonomies, one for make and one for model. There would be a taxonomy field for the model term that allowed selecting the make term.
I would filter the values shown in the model field based on the selection made in the make field. This may actually require not using taxonomy fields, but I don’t know this for sure. I would need to look at the ACF JS API documentation to see if the AJAX request on this field could be altered to include the value selected in make. The exact details of this research would make the decision on how to proceed.
I would create my an acf/save_post action that would create the association between the model term and the make term when a new model term is added (basically look to see if the association already exists and if it does not then create it. Basically creating a parent/child association between these to taxonomies. Spitting the make and model taxonomies would also make it much easier to filter by these two fields and in the case of a model that is shared between 2 makes would mean that duplicate model entries would not be created.
Assuming that the client also wanted urls like /product/make/$make/model/$model/
I would also add custom rewrite rules to accomplish this.
It is was me I would likely build something myself using jQuery and AJAX and either have a button to show more or build my own infinite scroll for it. I don’t have any examples or I would share them. I don’t generally work with gallery fields and there are several pieces that all need to work together to build something, probably would be a couple of hours work.
I do have an old example of a load more for a repeater that uses a button https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/repeater-ajax-load-more, the principle is the same. The only difference with infinite scroll is that you need to detect when the page is scrolled far enough to trigger the request instead of using the link.
Don’t thank me for the plugin, I’m just another developer like you that uses ACF for nearly everything I do and I could not do what I do without it either.
I did some testing on and I cannot recreate it.
What editor is shown is determined by the last action a user takes in a wysiwyg field, any field. WP, not ACF stores a value on the last selection, visual or text and the next time the editor is loaded all of the wysiwyg fields will be set to this tab.
I do not know how or where this value is stored by WP, but you can see it in action on an user where it is working correctly. Open any post, change the mode of any wysiwyg editor, wait a second or 2 and reload the page, all editors should not be in the last mode selected.
Further testing shows that this selection is stored somewhere and is not related to a cookie value. Clearing cookies for the site doe not effect it. Again, looking for how this is stored I can find nothing. I did find this https://wordpress.stackexchange.com/questions/41412/rich-text-editor-settings-persist-throughout-all-rich-text-editors however, I do not see the meta value in the DB changing.
The only thing that I can think of is the there is a filter on the WP hook user_can_richedit that is returning false for this user type.
Solved issue 1
add_filter('acf/fields/taxonomy/result/key=field_605b7c5cc9dc9', 'my_acf_fields_taxonomy_result2', 10, 4);
function my_acf_fields_taxonomy_result( $text, $term, $field, $post_id ) {
$text = $term->name;
return $text;
}
Feedback and issue 2 remains for the feature save/create terms.
2.1) How to turn of the parent selector on specific field.
2.2) Change the name of the tooltip/dialog(modal) with label name instead of the taxonomy.
2.3) In the dialog(modal) replacing the label of parent with custom label name of a field to field basis.
Ideally the should be some unique identification for the modals
If you are talking about having a load more feature on the front end of the site. ACF does not have any code for the front end for fields and you need to build. There is an example of this here https://connekthq.com/plugins/ajax-load-more/examples/advanced-custom-fields/gallery/
Hello everybody,
I proud to found a solution by myself ;-).
I share it if someone would like to use ACF Gmap as a Gutenberg Block.
You can close the thread.
Here is my block code.
Best.
Pierre
<?php
/**
* Gmap Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
*/
// Create id attribute allowing for custom "anchor" value.
$id = 'gmap-' . $block['id'];
if( !empty($block['anchor']) ) {
$id = $block['anchor'];
}
// Create class attribute allowing for custom "className" and "align" values.
$className = 'gmap-block';
if( !empty($block['className']) ) {
$className .= ' ' . $block['className'];
}
if( !empty($block['align']) ) {
$className .= ' align' . $block['align'];
}
$place = get_field( 'gmap' );
if( $place ):
$lat = esc_attr( $place['lat'] );
$lng = esc_attr( $place['lng'] );
$zoom = esc_attr( $place['zoom'] );
$place_lat = str_replace( ',', '.', $lat);
$place_lgn = str_replace( ',', '.', $lng);
?>
<div id="<?php echo esc_attr($id); ?>" class="acf-map" data-zoom="<?php echo $zoom; ?>">
<div class="marker" data-lat="<?php echo $place_lat; ?>" data-lng="<?php echo $place_lgn; ?>"></div>
</div>
<?php endif; ?>
Thanks for your help John…just hearing that what I had should work in theory was what I needed to look elsewhere. I realized that I was missing the specification of what type of posts to query, like
$args = array(
'post_type' => 'service',
'meta_key' => 'type',
'meta_value' => 'Litigation'
);
Which works perfectly now. Cheers!
What does the rest of your query look like. I don’t see any reason that this should not be working.
Did the field originally allow multiple selections and then changed to only allow 1?
Similar question here https://support.advancedcustomfields.com/forums/topic/check-box-values-from-gravity-form-not-stored-in-acf-check-box/
There is no choice value of “Small”, so your query should not return any posts.
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.