I have a text field which includes a URL.
$url = get_field('global_contrib_url', 'options');
I have parsed the URL to identify the host.
$contrib_url = parse_url($url);
$contrib_domain = $contrib_url['scheme'] . "://" . $contrib_url['host'];
Then I set up conditional statements to compare that domain to the value in the field:
if($contrib_domain == 'https://secure.example1.com'):
elseif($contrib_domain == 'https://secure.example2.com'):
elseif($contrib_domain == 'https://donate.example3.com'):
endif;
However, unique code I have for source
in example3.com
conditional statement shows up as the source
for either example1.com
or example2.com
and I cannot figure out why.
ACF gallery not updating the images in webp.
Using siteground server & their webp service. For post thumbnails(<?php the_post_thumbnail('size'); ?>
) webp images are loading fine and automatically on the website but for ACF gallery field(using foreach loop and ID) still loading the old jpg/png images.
https://staging3.plutontravel.com.cy/packages/summer-singapore-phuket/
The banner slider been created using ACF Gallery field.
On this screenshot, is shown how all the images been converted to webp by siteground.
https://capture.dropbox.com/TYvFFUwhmqkPBsUr
One of my text fields is saving a value with apostrophe such as “Jim’s Store” in the database. When I tried to retrieve it using WP_Query()
, it’s not returning any value.
I noticed that if I used stripslashes()
in my search query args, it returned me the correct value: 'value' => stripslashes($_POST['store'])
My concern is that stripping slashes could potentially introduce security vulnerabilities including the risk of SQL injection?
Is there a better way to address this?
Our application generates alerts and we use ACF fields to hold email subject lines and bodies. The subject line for one type of alert has never worked properly. Because I couldn’t see anything I assumed it was empty but, in working with Local and MailHog to retool the alerts, I learned that there is a subject line, but it’s polluted with encodings, generating
Subject: =?us-ascii?Q?OSBS:_Your_Use_Application_has_been_Submitted_a?= =?us-ascii?Q?nd_is_Under_Review?=
instead of
Subject: OSBS: Your Use Application has been Submitted and is Under Review
Our methods work for email bodies and for other alert subject lines. It’s all baffling: how it got like this, how to find the root cause, how to fix it.
I’d appreciate any insights, thanks, I haven’t seen anything like this in many years.
I have a relationship field that displays a featured post, page, custom post type (such as a case study).
I want to display the title of a custom post type within the relationship field, so it shows whether it’s a case study, article, etc.
This is my code so far – have got a bit stuck as I can only get it to return ‘page’.
<?php
$featured_posts = get_field('select_post_or_page');
if( $featured_posts ): ?>
<?php foreach( $featured_posts as $featured_post ):
$permalink = get_permalink( $featured_post->ID );
$title = get_the_title( $featured_post->ID );
$excerpt = get_the_excerpt( $featured_post->ID );
$image = get_the_post_thumbnail( $featured_post->ID );
?>
<article class="row">
<div class="col-6">
<p>Custom post type title here</p>
<h2><a>"><?php echo esc_html( $title ); ?></a></h2>
<p><?php echo $excerpt; ?></p>
<a>" class="btn">Read more</a>
</div>
<div class="col-6">
<?php echo $image; ?>
</div>
</article>
<?php endforeach; ?>
<?php endif; ?>
</div>
We are updating out website currently, and added ACF, we have 2 templates, one for homepage and the other we use for our 56 locations landing pages.
Everything is great, but I cant get our booking button to work properly, currently when you click book now, it will open our booking platform (Boulevard) by sliding out on the page and shows all stores, but we would like to have each landing page open directly to their booking section. The platform allows this, but I’m unsure how to add it to a button on ACF.
Here is a example location, on the top you click book now, and it shows all the locatios.
https://vj8mbnx6h7v.c.updraftclone.com/locations/keene/
The button is linked to our domain.com/location/keene/#book-now
But this tutorial shows how to have it open directly to the location:
https://support.boulevard.io/en/articles/5941527-self-booking-link-to-specific-items-or-categories
We successfully did this before using WPBakery but now when I try to add it, the button disappears and it becomes a sting of text and looses the button.
How can I make the top right book now button use this code:
Each location has a unique code given, for example here are 3 locations:
Utica: blvd.openBookingWidget({ urlParams: { locationId: ‘0e34d867-7641-4d0e-baf0-2cbd9cffa4b3’, path: ‘/cart/menu/Floatation Therapy/s_2ed759cf-586b-4c57-9594-dc4f0882dc77’, visitType: ‘SELF_VISIT’ }});
Abq: blvd.openBookingWidget({ urlParams: { locationId: ‘4996c667-9811-4071-add0-680c0d5f41c6’, path: ‘/cart/menu/Floatation Therapy/s_2ed759cf-586b-4c57-9594-dc4f0882dc77’, visitType: ‘SELF_VISIT’ }});
Alexandria: blvd.openBookingWidget({ urlParams: { locationId: ‘cdcd6aad-ab17-4694-a37d-c95e846fc203’, path: ‘/cart/menu/Floatation Therapy/s_2ed759cf-586b-4c57-9594-dc4f0882dc77’, visitType: ‘SELF_VISIT’ }});
How an I implement this? We use a PHP template, and dont currently add things to functions.php, we just add it to the template ad call the code.
Any help would be amazing!
Do ACF Blocks support the @wordpress/interactivity API?
I’m looking to create a custom navigation menu that requires more customization than what the default Gutenberg nav block allows, so I’m creating my own custom nav ACF block. The default block uses the interactivity API to trigger things like the modal window opening on mobile devices, and I’d like to leverage that for my menu, without having to include any external libraries.
My block.json file:
{
"name": "acf/menu",
"title": "Advanced menu",
"description": "A custom menu module with expandable mobile menus",
"script": "file:./interactivity.js",
"style": [ "file:./menu.css" ],
"category": "theme",
"icon": "menu",
"keywords": ["menu", "nav", "mobile"],
"acf": {
"mode": "preview",
"renderTemplate": "menu.php"
},
"supports": {
"anchor": true,
"jsx": true,
"interactivity": true,
"mode": false
}
}
As per the API handbook, I’ve tried adding “data-wp-interactive” to my menu, but nothing happens. (It’s very possible I’m missing a step, or forgetting something though)
Any ideas?
I would like to block a user from modifying a field, but from being able to view it. Will this be possible?
I have a Button Group field called Registration, with 3 options:
Required
None
Optional
If the value of Registration is anything but None, I would like to require a value for a URL field called Registration Link, but obviously I don’t want to require a value if registration is None (that is, not required).
That seems not to work.
Is there another way to do this?
I have a feeling that I’m just missing something here about ACF custom post types.
This is for a congregational website, and one of the sections is about adult classes that are offered. Each adult class has specific data associated with it: start date/time, end time, recurrence, facilitator, format (in person / Zoom / hybrid), etc.
I have ACFs in use for standard post types that have to do with events, and I have edited the code that pulls in and displays the posts based on start date/time, etc. That works just fine, and most of our posts are about specific events, although we do have some general announcements.
I realize that I *could* just add ACFs for the adult classes to the field groups used for all posts and update the code that handles all the posts, but that seems like overkill since only a small percentage of our posts (maybe 2-3 dozen max each year out of several hundred) are related to adult classes.
I was hoping that by creating a custom post type for adult classes, I could create a field group that would only apply to that post type, and I could then display the data in those fields when I display those custom posts. I guess I was expecting a PHP template that I’d be able to edit like I edited the template for the generic posts.
So my question is: is there a way to use a custom post type to display the values stored in fields, or am I just out of luck?
Thanks.
I created an ACF Form and use CPT. The form creates a new CPT but I am trying to have the “Inventory ID” field be unique. I have the code below which works but it only does it when adding a new CPT from the WordPress Dashboard side rather than the frontend using the ACF Form. The ACF Form still allows for duplicate ID’s.
// Unique ID field
add_filter('acf/validate_value/name=inventory_id', 'acf_unique_value_field', 10, 4);
function acf_unique_value_field($valid, $value, $field, $input) {
if (!$valid || (!isset($_POST['post_ID']) && !isset($_POST['post_id']))) {
return $valid;
}
if (isset($_POST['post_ID'])) {
$post_id = intval($_POST['post_ID']);
} else {
$post_id = intval($_POST['post_id']);
}
if (!$post_id) {
return $valid;
}
$post_type = get_post_type($post_id);
$field_name = $field['name'];
$args = array(
'post_type' => $post_type,
'post_status' => 'publish, draft, trash',
'post__not_in' => array($post_id),
'meta_query' => array(
array(
'key' => $field_name,
'value' => $value
)
)
);
$query = new WP_Query($args);
if (count($query->posts)){
return 'This Value is not Unique. Please enter a unique '.$field['label'];
}
return true;
}
Is there any way to have the ACF Form on the front end validate for a unique value as well or is it only for on the WP Dashboard side? Thanks!!
Hello everyone,
I’ve only been working with ACF for a short time.
I created a select box using ACF, which is then output to the website using Elementor Pro.
For example, if the term “gum arabic” is selected, the text “stabilizers” should appear before this term. Or if the terms “lactic acid” and “citric acid” are selected, the term “acid regulators” should appear before them.
If the terms are not selected, nothing should appear.
Here is the link to the website:
http://dein-elabel.de/elabel/baden-markgraefler-land-grauburgunder-trocken-qba/
Does anyone know how to implement this?
Thank you and best regards
Florian
Basically my question revolves around how this all works…
Say for example I create 2 custom post types with the following fields:
1. RESIDENT
—–RESIDENT NAME FIELD
—–APARTMENT NUMBER FIELD (linked to below field/containing data from APARTMENT CPT)
2. APARTMENT
—–APARTMENT NUMBER FIELD
—–RESIDENT NAME FIELD (linked to above field/containing data from RESIDENT CPT)
AND each of the above custom post types will contain data from the other. So for example, a RESIDENT may be assigned to an APARTMENT, giving them an APARTMENT NUMBER and vice versa…
So now for example, when I create a RESIDENT named Anita and how can I give her an APARTMENT NUMBER (ie. LINK the two data to each other so they work properly together throughout the front and back-ends of the website)?
Is this something I need to code EXTRA or does all of this happen automatically via the settings in the plugin?
Do I need to use the RELATIONSHIP FIELD for this or is that for something different?
So, when I go to add a new RESIDENT via the Add New Resident Admin page and then how can I then add the APARTMENT NUMBER in such a way that it will pre-populate from the already currently available APARTMENTS already added or the other way around, when I go to add an APARTMENT, I can then add the RESIDENT from a pre-populated list of already added RESIDENTS?
So I hope this is making sense here…
So I am assuming that I can add all the data in the back-end and then create the template pages programmatically to pull whatever data I need for the front-end, and I get that, but my question arises when I am creating them in the back-end, will they be aware of each other (linked) or will I have to manually update each custom post types additions to reflect the status of the other essentially having to remember to update the APARTMENTS data to reflect any newly added RESIDENTS and vice versa any time a new one is added so that – that data will be available to pull from on the front end..? ..but then this would essentially mean every time a new RESIDENT is added, I would have to add content twice, manually going into the linked CPT to then like it from the reverse side…(OMG I don’t know if I am explaining this properly!!!)
Ok, well this is getting so long and confusing. I hope this is making sense to somebody!!
Thank you in advance to anyone willing to offer an answer or even some insight!! It will be very much appreciated!!
Can someone please help me understand the issue with the ACF Custom Blocks?
Based on official tutorial:
https://www.advancedcustomfields.com/resources/create-your-first-acf-block/#:~:text=%27%22%20%27%3B%7D-,//%20Create%20class%20attribute%20allowing%20for%20custom%20%22className%22%20and%20%22align%22%20values.,-%24class_name%20%3D%20%27testimonial
Let say I created a basic ACF Custom Block that outputs a simple DIV
with ‘customClassName’, taken from ‘ADDITIONAL CSS CLASS(ES)’ in Block’s ‘Advanced’ tab.
The PHP Template, based on tutorial, should output the rendered result in BackEnd and FrontEnd as:
<div class="'.$block['className'].'">Some text here...</div>
and with the ‘huge-padding’ $block[‘className’] should look like this:
<div class="huge-padding">Some text here...</div>
The problem:
The ACF output would assign the same $block[‘className’] to the block-editor-block-list__block wrapping container as well in the BackEnd.
The output in the BackEnd would have TWO ‘huge-padding’ and would look like this then:
<div ... data-type="acf/wpo-acf-myblock" class="block-editor-block-list__block wp-block ... huge-padding">
<div class="huge-padding">Some text here...</div>
</div>
Notice that both of the containers now have ‘huge-padding’ class that looks messy/confusing in the backend. And the users could have various custom classes like: red-border, xl-margin, framed, etc.
My question:
Is there a way to fix this behaviour without:
– disabling the ‘customClassName’ [and using the ACF custom-inner-class field]
– separating the output for Front-End with $block[‘className’] and Back-End without $block[‘className’]?
Thank you for your assistance.
– Ivan
1- My issues is: the new articles, moved from “wordpress > articles” to a new post type made by ACF, cannot read the new category (taxonomy with hierarchy) and tag (taxonomy without hierarchy) that I created on ACF.
For example, based on my theme, the category of an article shows above the article’s title. Now, the articles under a new post type shows the old category, but not the the new category (taxonomy with hierarchy).
based on my theme, the tag of an article shows at the end of the article. Now, the articles under a new post type shows the old tags, but no the new tag (taxonomy without hierarchy).
A friend of mine recommended me to build a new template for single post for the new post type, but I’m wondering if there is any other ways to do it. Thank you.
And my next question would be…if this works, how I can make the “apprearance > widgets > mian sidebar” to read all category or tag from different post types…
Thanks for your answers.
I am trying to create a custom query in my template file that filters posts by whether the end_date ACF is after today (event has not ended yet), and then order the output by the value in the event_start ACF. But I can’t seem to get my query right:
$today = date('Ymd');
$thePosts = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 10,
'meta_key' => 'event_start',
'meta_query' => array(
array(
'key' => 'event_end',
'value' => '".$today."',
'compare' => '>'
)
),
'order' => 'DESC',
'orderby' => 'meta_value',
'post_status' => 'publish',
));
Dear people,
I’ve quietly been struggling with the issue below for quite some time and have now decided to seek help through this forum.
I have created two taxonomies named “Model” and “Modeljaar” (Model Year). Additionally, I’ve set up an ACF field group linked to WooCommerce products.
Now, when specifying the compatibility of a WooCommerce product, I can choose both the “Model” and the “Model Year.”
However, if, for instance, I have 3 models – Volvo, Volkswagen, Audi – and model years such as “2015, 2016, 2017, 2018,” I encounter a problem.
For example, when I select Volvo and check model years 2015 and 2016, and also select Volkswagen and check model years 2017 and 2018, an issue arises.
The system fails to distinguish, assuming that Volkswagen is also linked to model years 2015 and 2016, as these model years are not linked to the “Model” taxonomy.
Ultimately, I need to create a search filter, such as with Search & Filter, and want to be able to search by model and model year. So, if you choose a Volkswagen now, you should also be able to find it when filling in the filter for model year 2015 or 2016.
I hope I’ve explained my problem clearly.
Do you have any ideas on how I can solve this?
Kind regards,
Miguel
Hi
I’m trying to dynamically add options to a select field on the admin page (edit page) via jquery/javascript. The idea is to be able to select a layoutblock from another page (fetched via rest api) so i can link to that section.
So far that works – the only problem with the dynamically added select options is that i can only save the value per option and not the label in the database.
I’m not able to save a different value and label. The value is automatically saved as label.
I tried both with normal select and select2 field – the behavior is the same.
Any hints on that?
Hi,
in recent days I had opened a request on the general forum of the repository regarding this question of mine.
I created some groups of fields in ACF that are shown in the sidebar, when inserting a product on woocommerce.
What I can’t do is show the fields in relation to the woocommerce categories.
Ex.
– woocat 1 -> group_1
– woocat 2 -> group_2In Position Rules I set the following rules:
1. Content Type = Product
2. User Role = Administrator
3. Item Taxonomy = woocat 1But despite this, the group of fields appears in every product page.
But having read the documentation for developers I created this function which should solve it and could possibly help other users too:
// Verifica se ACF è installato prima di utilizzare i filtri ACF
if (function_exists('acf')) {
add_filter('acf/load_field/name=attributo_montaggio', 'campoextra_acf_montaggio');
function campoextra_acf_montaggio( $field ) {
global $current_screen, $post;
// Verifica se l'utente corrente ha le autorizzazioni necessarie
if (!current_user_can('edit_posts')) {
// L'utente corrente non ha le autorizzazioni necessarie, esci
return $field;
}
// Ottieni i termini della categoria corrente
$terms = get_the_terms($post->ID, 'product_cat');
// Verifica se $terms è un array non vuoto
if (is_array($terms) && !empty($terms)) {
//$category_id = $terms[0]->term_id;
$category_name = $terms[0]->name;
// Array di nomi di categorie da confrontare
$allowed_categories = array(
"Cat Name 1",
"Cat Name 2",
// Aggiungi altri nomi di categorie secondo necessità
);
// Verifica se non siamo in modalità amministratore o se il tipo di post non è 'product' o se l'ID della categoria non è nell' array
if ((!is_admin() && $current_screen->post_type != 'product') || !in_array(strtolower($category_name), array_map('strtolower', $allowed_categories))) {
return false;
}
}
return $field;
}
}
I used the load filter and not the prepend.
Do you think it can be improved?
Thanks
Newbie, here. I have added ACF fields to images in WP Media library. I believe that I’ve set up the fields correctly (in a field group) and connected the group to all attachments. When I go into the Media library, I see the fields and am able to edit them in wp admin. However, I am getting nothing when I do get_field in my PHP code (in functions.php). See code below.
I’m referring to the post ID directly to assure context. Also, there will be several images on a single page, so I want to identify the one I’m talking about specifically.
Any ideas?
function artwork_shortcode($atts) {
// Extract the attributes
$atts = shortcode_atts(
array(
'src' => '', // Default image URL
),
$atts,
'artwork'
);
// Your PHP code here
$image_url = esc_url($atts['src']); // get the image URL from the shortcode attribute
$post_id = attachment_url_to_postid($image_url); // get the image post ID from the image URL using the WordPress function
$artfile = get_field('art-media-file', $post_id); // get value of a flag that this is art file media using the post ID
$title = trim(get_field('art-title', $post_id)); // get title using the post ID
$title = trim($title,'"'); // remove quotes
$year = trim(get_field('art-year', $post_id)); // get year using the post ID
$dimensions = trim(get_field('art-dimensions', $post_id)); // get dimensions using the post ID
$medium = trim(get_field('art-medium', $post_id)); // get medium using the post ID
$availability = get_field('art-availability', $post_id); // get availability using the post ID
$output = '';
if( $artfile && !empty($title) ) { // if it's an art file with a title
$output .= '<div class="art-details-card">';
$output .= '<h2><em><strong>' . $title . ',</strong></em>';
if (!empty($year)) {
$output .= ' ' . $year;
}
$output .= '</h2>';
if (!empty($medium)) {
$output .= '<p>' . $medium . '</p>';
}
if (!empty($dimensions)) {
$output .= '<p>' . $dimensions . '</p>';
}
if ($availability ) { // if it's available
$output .= '<p><strong>AVAILABLE</strong></p>';
}
$output .= '</div>';
}
// Format the HTML code for the pattern
$debug_msg = '';
$debug_msg = '<!-- Vars: image_url = ' . $image_url . ', post_id = ' . $post_id . ', artfile = ' . $artfile . ', title = ' . $title . ', year = ' . $year . ', dimensions = ' . $dimensions . ', medium = ' . $medium . ', availability = ' . $availability . ' -->';
$html_out = $debug_msg . '
<div class="art-container" style="position: relative;">
<img src="' . $image_url . '" alt="Artwork image" />
'. $output . '</div>';
return $html_out;
}
endif;
add_shortcode('artwork', 'artwork_shortcode');
I have two related custom post types (STORIES and CONTRIBUTORS) and have used a Relationship field to connect them together – so you can go into each story and selecting a number of contributors.
Question: How best to show the CONTRIBUTORS related to a STORY on the front-end?
The core Query Loop block does almost everything, but it can’t filter based on that relationship field – i.e. show just the CONTRIBUTORS that have been associated with that particular STORY.
How would I go about doing this? Is a block variation of the Query Loop the way to go?
Ideally I want to create an html template for the STORY post type and include this as part of it so that the user simply creates their story content and associates several CONTRIBUTORS to the post and it dynamically shows the correct ones on the front-end.
Any assistance much appreciated.
Jamie
Hi, I thought figured this out but I guess I jumped the gun. I am trying to auto calculate the a number field by the total amount of checkboxes that are checked. I have multiple custom fields that I am doing this with.
The top one works perfectly but when I add the second one and so on, it gives me an error.
count(): Argument #1 ($value) must be of type Countable|array
add_action('acf/save_post','calc_titles');
$post_id = 'teams';
function calc_titles($post_id) {
//First Part that works
$value = count(get_field('16th_region_title_year_won'));
$sixteen = "total_16th_region_titles";
update_field($sixteen,$value,$post_id);
//Second Part
$value = count(get_field('3rd_region_title_year_won'));
$third = "total_3rd_region_titles";
update_field($third,$value,$post_id);
}
Thanks!
I added a new field setting with this function (from the documentation)
function my_admin_only_render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __( 'Admin Only?', 'my-textdomain' ),
'instructions' => '',
'name' => 'admin_only',
'type' => 'true_false',
'ui' => 1,
), true ); // If adding a setting globally, you MUST pass true as the third parameter!
}
add_action( 'acf/render_field_settings', 'my_admin_only_render_field_settings' );
I want the new settings to appear only on a specific field group. How should I proceed? I tried a few different things without success.
(as a side-question, less important: is there a way to determine the position of the new setting?)
I have a series of child Pages, all of which can belong to one of three different Parent Pages. Each of these Child Pages calls in a particular field, depending on which Parent is selected.
When I do this using the field rules, it works perfectly. E.g. a User creates a new Page then selects a Parent for the Page and then the correct custom field for that Parent type appears.
However, some of my Authors are very, very inexperienced and often forget to assign a Parent to a new Page. I have tried assigning a jQuery confirm alert on Page Publish to remind Authors to assign a Page to a Parent but the more experienced Users find this annoying.
I have got round this by creating an Admin Dashboard widget that contains links to create a new Page with the Parent pre-selected. I’ve done this by adding the Parent ID to the URL of the new post:
https://www.example.com/wp-admin/post-new.php?post_type=page&parentid=1
Then I have some code in functions.php to test for this:
function my_preselect_parent() {
if(!isset($_GET['parentid']) || empty($_GET['parentid'])) {
return;
}else{
$ppid = $_GET['parentid'];
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#parent_id').val(<?php echo $ppid; ?>);
});
</script>
<?php
}
add_action('admin_head-post-new.php', 'my_preselect_parent');
This works perfectly.
However, my issue is – how do I now call the right custom field in? Is there a way to programmatically call in a custom field to the new post screen?
Hello ACF Support,
I’m encountering a challenge with nested Advanced Custom Fields (ACF) repeater fields on my WordPress site, specifically involving conditional logic and how it’s handled on the front end.
Setup:
I have a nested structure in my ACF fields, where plaintiff_injury_part_1 is a select field within a repeater field plaintiffs_injuries, which itself is nested within another repeater field plaintiffs_test.
The plaintiff_injury_part_1 field is a select dropdown that triggers conditional logic, displaying different injury types ( amputation, and abdomen which is abbreviated to “abdo” etc.) based on the selection.
Each injury type is a select field within the same repeater row.
Issue:
When an editor changes the injury type from one category to another (e.g., from abdo to amputation), the front end still displays both the new and the previous selections, instead of just the updated one.
I have implemented JavaScript to set the non-selected injury field to null when a different injury type is selected, and this seems to work in the admin area (the non-selected injury field resets to its default ‘-Select-‘ option). However, the front end still shows both injuries.
I’ve also modified my shortcode that outputs these fields to check for null values, yet the issue persists.
What I Need:
I’m looking for a way to ensure that when an injury type is updated in the backend, only the latest selection is reflected on the front end, and any previous selections under different injury types are not displayed.
Code Samples:
Here is the code for creating the short code for these fields (there is some debugging language left in there):
<?php
function acf_repeater_field_shortcode_plaintiff($atts) {
global $post;
if (!$post) return 'No global post object available';
$atts = shortcode_atts(
array(
'field' => 'plaintiffs_test',
),
$atts,
'acf_repeater_field_plaintiff'
);
$output = '';
if (have_rows($atts['field'], $post->ID)):
while (have_rows($atts['field'], $post->ID)): the_row();
$output .= '<div class="repeater-item">';
// ... other fields ...
if (have_rows('plaintiffs_injuries')):
while (have_rows('plaintiffs_injuries')): the_row();
$output .= '<div class="plaintiffs_injuries">';
// Debugging lines
$amputation = get_sub_field('amputation');
$abdo = get_sub_field('abdo');
$output .= "<p>Debug Amputation: " . esc_html(var_export($amputation, true)) . "</p>";
$output .= "<p>Debug Abdo: " . esc_html(var_export($abdo, true)) . "</p>";
// Check for non-null and non-'null' values
if (!empty($amputation)) {
$output .= '<p><strong> Amputation Injury: </strong>' . esc_html($amputation) . '</p>';
}
if (!empty($abdo)) {
$output .= '<p><strong> Abdominal Injury: </strong>' . esc_html($abdo) . '</p>';
}
$output .= '</div>';
endwhile;
endif;
$output .= '</div>'; // Close .repeater-item div
endwhile;
else:
$output = 'No data found in the ACF Repeater Field.';
endif;
return $output;
}
// Now the shortcode
add_shortcode('acf_repeater_field_plaintiff', 'acf_repeater_field_shortcode_plaintiff');
And here is the javascript created to void the field that is not selected, when one makes a new choice.
function my_acf_admin_custom_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Trigger this when an ACF field within a repeater changes
$(document).on('change', '.acf-repeater [data-name="plaintiff_injury_part_1"] select', function(e) {
var $thisSelect = $(this);
var $repeaterRow = $thisSelect.closest('.acf-row');
var selectedValue = $thisSelect.val();
// Reset the 'abdo' field if 'amputation' is selected, and vice versa
if(selectedValue === 'amputation') {
$repeaterRow.find('[data-name="abdo"] select').val('').trigger('change');
} else if(selectedValue === 'abdo') {
$repeaterRow.find('[data-name="amputation"] select').val('').trigger('change');
}
});
});
</script>
<?php
}
Any guidance or insights into what might be causing this behavior and how to resolve it would be greatly appreciated. Thank you for your assistance!