I followed Damon Cook’s extremely helpful tutorial here on creating an ACF slider block w/ Swiper. One thing I cannot figure out is how to get some core block features to appear in the editor, such as spacing, even though I’ve included it in the supports
section of the block.json
file. I’m attaching the full slider block.json
file below- I can get the align, anchor and class name options to appear in the editor sidebar, but I don’t see any of the spacing options. Anyone know what might be going on here? Note that I am not using a theme.json file, so I’m not sure if that’s a factor. On a related note, I’m also not seeing any custom dimensions in the sidebar- in this case, an option for min-height (the “Dimensions” section doesn’t appear at all).
{
"name": "acf/slider",
"apiVersion": 2,
"title": "Slider",
"description": "Display a slider",
"category": "media",
"icon": "slides",
"keywords": [
"slider",
"slideshow",
"carousel"
],
"acf": {
"mode": "preview",
"renderTemplate": "template.php"
},
"attributes": {
"align": {
"type": "string",
"default": "full"
},
"style": {
"type": "object",
"default": {
"dimensions": {
"minHeight": "30vh"
}
}
}
},
"supports": {
"color": true,
"align": [
"full",
"wide"
],
"fullHeight": true,
"spacing": {
"margin": true,
"padding": true,
"blockGap": true
},
"anchor": true,
"className": true,
"dimensions": {
"minHeight": true
},
"mode": false
},
"example": {
"attributes": {
"align": {
"type": "string",
"default": "full"
}
},
"innerBlocks": [
{
"name": "acf/slide",
"attributes": {
"className": "swiper-slide",
"content": "Slide #1"
}
},
{
"name": "acf/slide",
"attributes": {
"className": "swiper-slide",
"content": "Slide #2"
}
}
]
},
"editorScript": [
"swiper-core",
"slider-init-editor"
],
"viewScript": [
"swiper-core",
"slider-init-front"
],
"styles": [
{
"name": "default",
"label": "Default",
"isDefault": true
},
{
"name": "complex",
"label": "Complex"
}
]
}
Hello, I’ve got a teaser snippet that pulls the taxonomy info for a custom post type and works fine when using a wpquery:
setup_postdata($post);
$postid = $post->ID;
$item_image = get_field("listing_image", $post->ID);
// TAXONOMY //
$taxonomy = 'types';
$terms = get_object_term_cache( $postid, $taxonomy );
$outputpill = '';
$i = 1;
$teasertype = '';
foreach($terms as $term) {
if ($i == 2) { break; }
if(!empty($outputpill))
$outputpill .= '';
$outputpill .= '<div class="cat cat-pill pill-'. $term->slug . '">'.$term->name.'</div>';
$teasertype = $term->slug;{}
$i++;
}
// BUTTON SWITCH //
if($teasertype){
switch($teasertype){
case 'article':
$ctaclass= "article";
$ctatext= "Read Now";
etc etc etc
When I use this snippet on another page that references these custom post types using a Post Object field, it throws an error when looking up the taxonomy:
Warning
: foreach() argument must be of type array|object, bool given in
/Users/louis.plante/Local Sites/smartvaultcom/app/public/wp-content/themes/smartvault-wordpress-website/inc/snippets/_incl_resources–teaser.php
on line
17
Code used:
<?php $post_objects = get_field('campaign_group1_item_resource'); ?>
<?php
if( $post_objects ):
foreach( $post_objects as $post):
setup_postdata($post); //set new $post_object
get_template_part( 'inc/snippets/_incl_resources--teaser' );
endforeach;
wp_reset_postdata(); //reset global $post
endif;
?>
(Cant send a Support ticket because Its detect me as spam I don’t know why)
Hi guys, how are you? Maybe I’ve found a bug. A time ago I’ve created ACF Groups to manage some information in Elementor Loop module. All was working fine until today. When I went to ACF Groups options I saw that it’s empty and the group is missing. The curious thing is that ACF still showing on front-end (see reference in attachments). Whats going on here? I deactivated all the other plugins and the problem persists. Can you help me? Thank you
Happy New Year to you Sir,
There’s no easy way to show ACF Field values on the frontend of our website.
This plugin called Advanced Views (https://wordpress.org/plugins/acf-views/) — helps to show any ACF Field value on the frontend.
You can see the demonstration of its power in this video — https://www.youtube.com/watch?v=fFz6OTeoiMI
I don’t know why someone should help ACF, when ACF can actually help itself.
SOLUTION
I asked that you should extend your ACF Shortcode ( https://www.advancedcustomfields.com/resources/shortcode/) , and give it the power to be able to translate all ACF Field values to the frontend.
You’ve still not done it. Why is that?
Why are you stubborn to implement this request?
IMPORTANT CONTEXT
98% of WordPress users are Drag-and-Drop users.
So they won’t code, and will never code.
You see, ACF had been stubborn, saying that it is built for Developers, and will therefore not bother to provide a way to translate ACF Field values to the frontend.
It’s time you stop that senselessness, and appeal to all WordPress users– through your ability to translate ACF Field values to the frontend simply by Shortcode, Dynamic content generators, Twig or whatever means.
For your clear information, Elementor didn’t create ACF, yet Elementor is making good money for being able to translate ACF Field values to the frontend, through its ACF integration and Dynamic Tag features.
Why should ACF lag behind in this feature, while people who didn’t create ACF are making money for being able to translate ACF Field values to the frontend?
ANOTHER SCENARIO
There’s this plugin called CMB2 (https://wordpress.org/plugins/cmb2 )
Now, that plugin can do what ACF does.
But ACF succeeded more than the CMB2 plugin because of 3 things:
1.) ADMIN UI: With ACF installed, we can easily add Custom Fields, and create Custom Post Types, plus Custom Taxonomies through the Admin UI.
But CMB2 required us to still insert the fields we need by specifically coding them into the plugin.
This was a bit difficult and complex– so ACF won the point here.
2.) FRONTEND VIEW
Page Builders like Elementor Pro, and other Page Builders, made it possible to display ACF Field values on the frontend.
There’s no easy way to do this with CMB2 Metabox plugin without writing code, as you can see here– https://cmb2.io/docs/bringing-metaboxes-to-the-front-end
So ACF won the point here again.
3.) BETTER SUPPORT
ACF had better support– we get quick and timely answers to questions, both on WordPress.Org, and also on the ACF Support Forums.
So a lot of users gravitated easily to ACF, and again, ACF won the point here.
If you look at these 3 points for ACF, you will notice that the strongest points that helped ACF to win against CMB2 Metabox, was because ACF had a Backend Admin UI where non-techie people can see what they are actually creating.
Then by some stroke of good luck, Page Builders like Elementor Pro, and other Page Builders, made it possible to display ACF Field values on the frontend.
These important frontend possibilities, are the main things that gave ACF its victory.
YOUR NOTION “FOR DEVELOPERS” NO LONGER STANDS
At no point ever, did ACF win and become popular because it was “for Developers” as you claim.
That notion didn’t really win you points and affection. It was your Admin UI and frontend display possibilities that scored you your winning points.
Your Backend UI View, and Frontend view by Page Builders like Elementor, is why ACF won people’s hearts.
So stop that pointless notion of “for Developers” and embrace the 98% of non-coders who made ACF popular and victorious in the Custom Field race.
Provide us with a way to display all ACF Field values in the frontend– by Shortcode, Dynamic content generators, Twig or whatever means.
2.) METABOXES — by using CMB2 and Pods( https://wordpress.org/plugins/pods) —- we can actually create Metaboxes.
Now, a Metabox is just a field container that holds a field.
When creating a Post in WordPress– Publish, Featured Image, Categories, Tags, Excerpt, and those other expandable and collapsible boxes we see on the right side, are Metaboxes.
I’m talking of these— https://prnt.sc/hNX1jzCViWFD
I am able to create such things (Metaboxes) with CMB2 and Pods.
I want to be able to create the same thing (Metabox) with ACF.
So beyond Custom fields, Custom Post Types and Custom Taxonomies, when will ACF make it possible for us to be able to create Metaboxes using ACF?
Needing to hear from you soon.
Regards.
I want to create a select field that is attached to the user role which, in itself is simple enough, but I’m unsure how to output this. Ideally, both label and value.
The docs suggest the following;
<?php
$field = get_field_object( 'color' );
$value = $field['value'];
$label = $field['choices'][ $value ];
?>
<p>Color: <span class="color-<?php echo esc_attr($value); ?>"><?php echo esc_html($label); ?></span></p>
How would I now amend this so it works for fields within a user profile?
I’m doing something like this for other fields;
<?php
$repeater = get_field('invoices', 'user_' . $current_user->ID);
$order = array();
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['invoice_number'];
}
array_multisort( $order, SORT_DESC, $repeater );
if( $repeater ): ?>
<?php foreach( $repeater as $i => $row ): ?>
<tr>
<td><?php echo $row['invoice_number']; ?></td>
<td><?php echo $row['invoice_date']; ?></td>
<td><?php echo $row['invoice_total']; ?></td>
<td class="invoice-actions">
<div>
<a target="_blank" href="<?php echo $row['invoice']; ?>" ><i class="fa-regular fa-eyes"></i></a>
<a href="<?php echo $row['invoice']; ?>" download><i class="fa-regular fa-cloud-arrow-down"></i></a>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
But I’m confused as to why this method doesn’t work on the select field.
Hi there! I’m not a developer, just a Dad that is trying to create a cool website for his Jazz Musician son. While I’m using Elementor, I’m also trying to minimize plugins. That said, I’ve created a Custom Post Type called “Gigs” to dynamically highlight upcoming shows that my son will be playing. I’ve also created a Custom Taxonomy called “Locations” to dynamically bring in Map, Location URL, and Image for instance. I cannot get any of these custom fields associated with the Locations Taxonomy to display. I’ve also created a second CPT called “Gig Locations” and tried to relate them to the Gigs CPT so that I could display its respective custom fields.
I can place an ACF Google Maps field directly in the Gigs CPT and it will display through the Elementor Google Maps widget. But the ACF Google Maps fields in either the Taxonomy or 2nd CPT will not display. When attempting to put custom PHP code snippets to “get_meta_terms” etc., nothing happens or the site crashes entirely.
Thanks in advance for your help!
qthornton.com
I inherited several sites created years ago. The developer did not use esc_html, esc_attr, or esc_url when outputting the_field(). I’m hoping I won’t have to manually escape all instances (hundreds) of the_field() when 6.2.7 releases, because it appears that will now be handled automatically.
Is that correct? I’m sure hoping so. That would save me many, many hours of work.
Hey all, I’m been beating my head against this issue for the last day and have not been able to track down what is causing this issue.
So, right now I have a custom post type I created called “gallery_slides” that we are using to make individual slides for a bootstrap carousel gallery.
I have created two separate ACF blocks:
Everything is working fine for the CPT portion so far. The gallery slides are being saved correctly and I can write them all to a page using WP_Query without any issues.
The problem comes into play when I try the add “gallery slides” using the ACF Relationship field in the block designed to render them to a page. When I add the first one, everything seems fine, when I add a second one from the relationship list, it immediately breaks the block, giving this error:
“This block has encountered an error and cannot be previewed.”
When I check the console, it’s also giving me a “TypeError: e is null, jQuery 5, onAppend…” error. When I click on the post.php link to see where the error occurred, it just says “originalMethod(…args);” If I remove the WP_Query and just try to var_dump the relationship field with a foreach() it still does the same thing.
If I save and refresh the page, the “gallery slides” I chose have been correctly saved, but if I change anything within the relationship field it breaks again. If I preview it, the “gallery slides” are being correctly rendered on the front end.
I have two other custom post types that are being used the same way and they work perfectly fine with the relationship field. They take the relationship field as a variable and run it through a foreach() that does a WP_Query for each one selected.
Does anyone have any idea what might be causing this? I feel like it’s something simple that I overlooking, so any help would be greatly appreciated.
Per ACF Pro Support’s suggestion, I’m posting this request here (I know this is a long shot).
Currently, the ACF Pro License only recognizes the string “stage” or “dev” in the domain name to automatically deem a particular site to be considered staging or development, which would not count against the valid license meant for production sites.
In my situation, I have a production site that uses http://www.mysite.com and an established staging/development site (well before ACF Pro License started recognizing staging sites) that uses devel.mysite.com.
However, I’m still forced to use my devel site as my production site for my lifetime license due to the very specific and restrictive “dev” string they’re looking for.
Therefore, I’d like to see the requirement expanded to include the string “devel” in that automatic development/staging site detection (or at least “dev*” where * is a wildcard).
That way, there’s no need to maintain yet another development site or having to switch licenses between production and devel site just to satisfy this very specific and restrictive requirement.
Why am I seeing these warnings all of the sudden?
At first I thought it’s because I used ampersand instead of " " so i changed it – but the warning is still there
I have a flexible content field that is defined as follows. The layout value is empty:
{
"key": "field_6576a2f9f2147",
"label": "Content",
"name": "content",
"type": "flexible_content",
"layouts": {}
}
Now fields are created dynamically in PHP, which I would like to summarise in layouts and add to the flexible content field.
I know that I can add a field to an existing group using the parent attribute of acf_add_local_field. But how can I add it to a Flexible Content field?
Not to do with the plugin directly itself, but I am a freelancer who opts to buy individual licenses for each of my clients. It would be really helpful if I could label licenses in my ACF account so I could quickly and easily see which license was for which site, and who’s needs renewing!
Greetings,
Hope you’re having a good day. I’m trying it for quite sometime but I couldn’t actually get it right.
-What I have:
I’ve a text field that intakes URL. I included the URL of my image (that I’m hosting via CDN). It is saved as ACF field and when I’m output it to just to debug, it is shown as image (if I use tag and pointing that as src)
-What I did:
I know there are functionalities to add in function.php that will take the text field and store it as image (uploading it to WordPress library) then setting it as post_thumbnail. I basically somehow did that and it worked out once. But I lost that code now
-What I actually want
Basically to replace the plugin FIFU, there are many plugins in my dashboard, I know coding so I thought of replacing it.
-What functionality I want in it
To take the URL from my ACF that is a text, set that as Featured Image (without saving it in media library). Please note, I don’t want it to be saved in media library since I’m using an image CDN and don’t want to increase my site load. Thanks a lot for your time. Hope I’ll get some help, it’ll mean a lot!
I am building a luxury real estate website, where they have both properties for sale and for rental.
I have a few filters (see attached), the main ones being “For Sale and For Rent” and then the Price Range filter
I would like the price range filter to be hidden when someone clicks on the filter option “For Rent” as the prices are on request only
Would that be possible?
Hi there,
I want to autogenerate title and slug from ACF fields and terms and I’ve already created a function which works nearly perfect. My only issue is, the date output is not working correctly. I don’t want the present date but the correct date from the two custom_fields from date picker. Here is the custom code:
// Create Auto Title for 'Veranstaltungen'
add_action('save_post', 'wpb_autogenerate_events_title', 10, 3);
function wpb_autogenerate_events_title($post_id, $post, $update) {
// Check if it's the 'events' CPT and if the title is empty.
if ('veranstaltungen' !== $post->post_type || !empty($post->post_title)) {
return;
}
// Fetch terms from 'category' and 'nameselection' taxonomies.
$category_term = wp_get_post_terms($post_id, 'veranstaltungskategorie', ['fields' => 'names']);
$nameselection_term = wp_get_post_terms($post_id, 'winzertax', ['fields' => 'names']);
// Fetch the 'date' custom field created with ACF Pro.
$date_start = get_field('datum_beginn', $post_id);
$date_end = get_field('datum_ende', $post_id);
$date_start_form = date( "dmY", strtotime($date_start));
$date_end_form = date( "dmY", strtotime($date_end));
// Combine the terms and the date to form the title.
$new_title = join(' <br>bei ', array_merge((array) $category_term, (array) $nameselection_term));
$new_titleslug = join('-', array_merge((array) $category_term, (array) $nameselection_term, (array) $date_start_form, (array) $date_end_form));
// Prepare the slug from the title.
$new_slug = sanitize_title($new_titleslug);
// Update the post.
wp_update_post([
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug, // This is the slug.
]);
}
Could you please help me why the output isn’t correct?
Hello,
in the documentation (https://www.advancedcustomfields.com/resources/query-posts-custom-fields/) at 4 we can see how to work with queries and a subfield of a repeater field.
Now I have a repeater field with two subfields and I tried the same way with an AND relation but it seems the relation will be ignored. The queries searchs for value of subfield A or subfield B.
Here’s my code so far
$meta_query[] = [
'relation' => 'AND',
[
'key' => 'spielzeiten_$_datum',
'value' => date('Ymd'),
'type' => 'DATE',
'compare' => '>=',
],
[
'key' => 'spielzeiten_$_datum',
'value' => date('Ymd', strtotime('+30 days')),
'type' => 'DATE',
'compare' => '<=',
],
[
'key' => 'spielzeiten_$_silberfilm',
'value' => 0,
'compare' => '=',
],
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'spielzeiten_$", "meta_key LIKE 'spielzeiten_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
Somebody have a hint for me how to fix this? So the query will search for posts where the Date is between now and 30 days in future AND is not a silberfilm?
I have an image repeater on a site. Without adding anything to the field, the site is automatically adding 2 rows and will not allow me to delete them. There is no requirement or minimum number so I’m stuck here.
I need to be able to use the value of a subfield to identify the row of data I need from either a Repeater Field or Flexible Content. I’d be grateful for any wisdom on which field type is best for this purpose.
My current thought is that a Flexible Content field would be best. I could create unique Layouts and use ACF’s built-in function to search for the layout I need to identify the row I need. I would never repeat the same layout in the same post.
Is my thinking correct here, or have I missed something?
Thanks for your feedback!
Using acf/render_field/type=image
, I’m echoing a script and appending some elements. The script is running as expected on top-level image fields, but while the elements always append, the script fails to run on dynamically loaded images within a flexible content repeater.
here’s the gist, getting an image within a field key—
add_action('acf/render_field/type=image', 'acf_image_pos');
function acf_image_pos($field){
$fieldKey = $field['key'];
echo '<script>
let img = document.querySelector("[data-key=\"'.$fieldKey.'\"]").getElementsByTagName("img");
console.log("Image: ", img[0]);
</script>';
}
Looking at the img[0] array, img.src is set as the current post.php url oddly, and the actual image URL isn’t stored anywhere else.
I tried running the functions within image.addEventListener("load")
and image.onload
, but that isn’t helping anything.
What is the hook for rendering of the image itself, not just the Image field?
Hi,
I have created a block called quote, and in the backend it calls the CSS like this:
https://example.com/wp-content/themes/theme-name/blocks/quote/quote.css?ver=6.4.2
The 6.4.2 is the current WordPress version.
But this causes issues because I want to update the file, but the file is now cached in browsers. How can I force this to change the version number?
Thanks
Shaun
I am trying to figure out how to count the number of users based off a field from ACF. In the past I have used something similar to this for default fields. But in this example, I always get 1, even though that is not the count. I don’t understand, is there something I need to do different for ACF? I’ve tried setting the value to Associate Member:associate_member for the dropdown list and changing the value in the script, but that just doesn’t work at all.
add_shortcode( 'show_assocaite_member', 'associate_member_count' ); //Count users
function associate_member_count() {
$aargs = array(
'meta_key' => 'membership_type', //any custom field name
'meta_value' => 'Associate Member', //the value to compare against
);
$ausers= new WP_User_Query( $aargs );
return $ausers->get_total();
}
I’ve previously used CPTUI, and recently migrated my CPTs and Taxonomies to ACF.
In order to get CPTs to show up in my archives, I used to make a call to cptui_get_post_type_slugs()
, which no longer works since I’ve disabled CPTUI.
What’s the right way to get the CPT slugs from ACF?
Here’s the full source I was using to merge my CPTs with the “normal” archive post types:
function my_cptui_add_post_types_to_archives( $query ) {
// We do not want unintended consequences.
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( (is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] ) ) {
$cptui_post_types = cptui_get_post_type_slugs();
$all_post_types = array_filter(array_merge( (array)get_query_var('post_type'), (array)$cptui_post_types ));
$post_type_filter = $_GET["post_type"];
if (!empty($post_type_filter) && in_array($post_type_filter, $all_post_types)) {
$query->set(
'post_type',
array ( $post_type_filter )
);
}
}
}
add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );
Hi
I’m using a section which has two repeater fields in. Is there a way to reuse content from one repeater in the other?
I reuse bits using the page ID, but haven’t done it before between repeaters. Is this possible?
// CASE: Team Blocks
elseif( get_row_layout() == 'team_blocks_section' ): ?>
<section id="team-carousel" class="<?php the_sub_field('section_colour'); ?> <?php the_sub_field('section_spacing'); ?> <?php the_sub_field('section_padding'); ?>">
<div class="container">
<div class="row">
<div class="section-centre centred-section">
<h2><?php the_sub_field('heading'); ?></h2>
<?php if( get_sub_field('text') ): ?>
<p><?php the_sub_field('text'); ?></p>
<?php endif; ?>
</div>
</div><!--row-->
<div class="row">
<?php // check if the repeater field has rows of data
if( have_rows('team_members') ):
// loop through the rows of data
while ( have_rows('team_members') ) : the_row(); ?>
<div class="col-lg-4 justify-content-center">
<div class="card text-center">
<?php
$image = get_sub_field('image');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
} ?>
<div class="card-body d-flex flex-column">
<h4><?php the_sub_field('name'); ?></h4>
<h5><?php the_sub_field('job_title'); ?></h5>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#<?php the_sub_field('popup_link'); ?>">
Read bio
</button>
<div class="mt-auto card-linkedin text-center">
<a href="<?php the_sub_field('tm_linkedin'); ?>"><img src="<?= get_template_directory_uri(); ?>/images/LI-In-Bug.png" alt="LinkedIn" /></a>
</div>
</div>
</div>
</div>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div>
<?php // check if the repeater field has rows of data
if( have_rows('team_members_popup') ):
// loop through the rows of data
while ( have_rows('team_members_popup') ) : the_row(); ?>
<!-- Modal -->
<div class="modal fade" id="<?php the_sub_field('popup_name'); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php the_sub_field('popup_name'); ?>Label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php
$image = get_sub_field('image');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
} ?>
<h4><?php get_sub_field('name'); ?></h4>
<h5><?php get_sub_field('job_title'); ?></h5>
<p><?php the_sub_field('tm_text'); ?></p>
</div>
</div>
</div>
</div>
<?php
endwhile;
else :
// no rows found
endif;
?>
</section>
Hi there,
Our WordPress have been updated and now all the web have a critical error.
The theme use in all page the “repeater fields” to make the content and now this function provoque a break code
Any one can help us?
Thank you
I have a very simple requirement to start.
I have a function that is called via a shortcode.
I know I can get a single value by doing the following
function cardkey() {
$user = wp_get_current_user();
$card_key = $user->card_key ;
return $card_key;
}
add_shortcode('testercode', 'cardkey');
So I want to return from a repeater something like this in a table
Name, Age, DoB, Phone, Email
I know how to setup the table header, so I then have this shortcode based off this page: https://www.advancedcustomfields.com/resources/repeater/
Not that I am trying just to get one value returned, but I get nothing, and there is data in the field.
function showmembers() {
$rows = get_field('household_members');
if( $rows ) {
$htmlcode = '<tr>';
foreach( $rows as $row ) {
$htmlcode += '<td>'.$row['age'].'</td>';
}
$htmlcode += '</tr>';
}
return $htmlcode;
}
add_shortcode('householddata', 'showmembers');