Hello!
Say I have a cpt “events”, and these events will happen on multiple dates. I then add a repeater (event_dates_repeater) so that I can add all the dates (event_date) in which the event will take place. I want to query these posts on a page so that the next event that’ll happen will always be the first shown. However, having multiple dates inside a repeater, it would have to work in such a way that when the first date of an event is already done, the query would now orderby the second closest date after $today.
I do understand how to order a query by a specific meta_key, but I’m not sure how to filter this meta just to use the next closest date subfield after today.
Thank you!
I’m having trouble getting a custom shortcode to display in a post.
I have a repeater named “my_presto_player” with two text sub fields named “presto_time” and “presto_topic”.
I created the following function:
function display_presto_content($content) {
return do_shortcode($content);
}
if (have_rows('my_presto_player')) {
while (have_rows('my_presto_player')) : the_row();
$timestamp = get_sub_field('presto_time');
$optional_text = get_sub_field('presto_topic');
if (!empty($timestamp)) {
$shortcode_content = '[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]';
return display_presto_content($shortcode_content);
}
endwhile;
}
add_shortcode('showpptime', 'display_presto_content');
Adding the shortcode [showpptime] doesn’t display any input from the sub fields at all.
What am I doing wrong? I’m very new to ACF.
When a gallery field is included within a Gutenberg block it does not consistently recalculate the number of columns that should be displayed when the block is swapped to the “edit” view.
Steps to reproduce:
It appears the Gallery block recalculates the number of columns that should be used whenever a resize event is fired (acf-pro-input.js lines 724-735). However when a user toggles the block into edit mode after the fields have already loaded in the sidebar, the fields move from the sidebar into the main content area (which is wider) and no resize event is fired, so column width is never recalculated. This means the gallery displays the same number of columns that were calculated when the field was displayed in a much narrower space, resulting in huge image containers and cumbersome user experience.
Suggested fix:
Column width should be recalculated when a block switches between the render preview and edit mode.
I don’t have a great workaround for this at the moment because there doesn’t seem to be an action triggered when a block switches from sidebar edit mode to block edit mode. My best solution at the moment is to trigger resize events manually on an interval whenever a gallery is first loaded, but it’s an ugly solution.
Example screenshots:
First, we have a block in Gutenberg that contains a Gallery field. I’ve selected the block with the sidebar open. The Gallery field is loaded and columns are calculated.
After that we click the edit (pencil) icon to swap the block into edit mode in the main column. The Gallery moves and becomes much larger, but images are still displayed in 2 columns instead of 3-8 columns resulting in a poor user experience. Resizing the window at this point forces the column count to update, but the column count will not update without a resize.
Hi,
I’m not great at creating functions, especially for the repeater field.
I have a repeater field named “myPresto_player”
with 2 text sub_fields: “presto_time” and “presto_topic”
Here is code the Presto Player developer advised I used to display the videos timestamp & optional content:
$timestamp = get_field('timestamp_field');
$optional_text = get_field('optional_text_field');
echo do_shortcode ('[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]');
Here is the function I have written for a repeater field using the above code:
function display_presto_content() {
if( have_rows('my_presto_player') ):
while( have_rows('my_presto_player') ) : the_row();
$timestamp = get_sub_field('presto_time');
$optional_text = get_sub_field('presto_topic');
if (!empty($timestamp)) {
// Build the shortcode with the timestamp and optional text
$shortcode = '[pptime time="' . esc_attr($timestamp) . '"]' . esc_html($optional_text) . '[/pptime]';
echo do_shortcode($shortcode);
}
}
First off, I’m not sure I have written the function correctly. Also, I’m not sure how to display the fields in a post.
Would greatly appreciate help with this.
I have what I am aware is a unique situation, and I already do this via code (so please, don’t tell me how to do that, it’s solved). I’m looking for a way to duplicate this with the ACF Options Page UX.
I have a parent Options Page with true/fasley checkboxes to enable features.
Some of those features have their own settings pages, which I want to only be available if the feature-box is checked.
I know how to do this in code. I have a check to get the specific option for the feature, and if it’s true, I have acf_add_options_sub_page()
run.
But this is something I have to do in code.
What would absolutely rule, would be if I could apply visibility rules to Options Pages. I can (and have) made a custom rule for “Is feature enabled” and I use it for per-page things (like ‘show this meta box if you’re on a single post and feature X is enabled). I would love to be able to extend this to options pages, so I could say “Show this option page if this feature is enabled.”
Again, I can do it in code, I do not need help there, but I’d love a UX so I don’t have to be the one to do it all the time 😀
So is there a way to ‘add’ Visibility Rules to the Option Page UX?
Hello,
I’m trying to create a rule in a custom field group in order to only show that field group in the “Packs” product category, but in the right side dropdown menu all the values are the same independently of what I choose on the left side.
Shouldn’t the right side of the rule dropdown show all product categories/taxonomies when I choose category or taxonomies on the left side?
Thank you in advance.
Hi,
Based on a specific category, I have trouble querying the posts from the Custom Post Type I created in ACF. However, if I remove 'category_name' => 'featured',
, the posts will show again. Still, the category name I wished to list without a link won’t show.
Below is my WP_Query code.
<?php $featured_slides = new WP_Query(
array(
'post_type' => 'project',
'posts_per_page => 10,
'category_name' => 'featured',
)
) ?>
<main class="common_margin">
<div class="hero_slide">
<div class="hero_slide-swiper swiper_container">
<?php if( $featured_slides->have_posts() ) : ?>
<div class="hero_slide-container swiper-wrapper">
<?php while( $featured_slides->have_posts() ) : $featured_slides->the_post(); ?>
<div class="hero_slide-item swiper-slide">
<div class="hero_slide-item--wrap">
">
<?php $img = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
if( has_post_thumbnail() ) : ?>
" class="hero_slide-item--img" alt="<?php the_title(); ?>">
<?php endif; ?>
<div class="hero_slide-item--desc">
<p>
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
</p>
<h4><?php the_title(); ?></h4>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); endif; ?>
<div class="swiper-pagination"></div>
</div>
</div>
</main>
Hi all,
I’ve been trawling the forums trying to find a solution for this.
We have an ACF field group called Additional Course Data group_5edb89be3792c which contains several fields including course_code.
This is assigned to Learndash Courses post type.
Each course requires a course_code which must be unique.
I’m trying to create a function that will reside in my child theme functions.php – that checks to see if the code is unique whenever a user clones or creates a new course and then checks the course_code is unique when they try to publish, and if it’s not unique, then display a warning “Course Code must be unique” so that the course_code is edited before publishing.
I’m not the greatest PHP developer in the world, so I’ve tried using codewp.ai to give me the basics, but I just can’t get it to work.
Any pointers would be greatly appreciated.I’ve been trawling the forums trying to find a solution for this.
This is where I’m at, but can’t get this to work
// Check that course code is unique
function cwpai_check_course_code_unique() {
global $post;
if (get_post_type($post) == 'sfwd-courses') {
$course_code = get_field('course_code', $post->ID);
$args = array(
'post_type' => 'sfwd-courses',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'course_code',
'value' => $course_code,
'compare' => '='
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$query->the_post();
if ($post->ID != $post->ID) {
$url = admin_url('post.php?post=' . $post->ID . '&action=edit');
$message = sprintf(__('The course code %s is already in use by %s. Please choose a unique course code.', 'cwpai'), $course_code, '<a href="' . $url . '">' . get_the_title() . '</a>');
?>
<div class="error">
<p><?php echo $message; ?></p>
</div>
<?php
}
}
}
}
add_action('admin_notices', 'cwpai_check_course_code_unique');
Hello everyone,
I have been trying all day to have FlexSlider work with Advanced Custom Fields Pro. I got the slider to work, but the image will not display. Here is my code below, any help would be greatly appreciated.
<?php if( have_rows('banner') ): ?>
<div class="flexslider">
<ul class="slides">
<?php while( have_rows('banner') ): the_row();
$image = get_sub_field('slide');
$title = get_sub_field('title');
?>
<li><img />" alt="<?php echo $title;?>"></li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
Hello ACF Community,
I’m facing an issue with updating ACF fields when duplicating pages in WordPress. Specifically, I’ve created a Custom Post Type called ‘locations’, and I’m trying to duplicate pages and update ACF fields associated with them. Unfortunately, the new data doesn’t seem to be stored in the ‘locations’ CPT.
Use Case:
I’m working on a site that involves a lot of locations, each as a separate page within the ‘locations’ CPT. I’m trying to duplicate existing pages (along with their ACF field data) to streamline the process of adding new locations. After duplicating a page, I want to update some ACF fields programmatically using update_field.
Code Example:
Here’s a simplified snippet of the code I’m using:
// Duplicating the post (this part works fine)
$new_post_id = wp_insert_post(array(
'post_title' => $original_post->post_title,
'post_type' => 'locations',
'post_status' => 'publish'
));
// Updating an ACF field (this is where the issue is)
update_field('field_name', 'new_value', $new_post_id);
Debugging Steps Taken:
Questions:
Thank you!
Paul
Hi everyone.
I want to insert a row layout from a Flexible Content field in one page (templates page) into the Flexible Content that is assigned to another page (Frontpage). The Flexible Content field group is the same. I am using the following code:
$template = get_field('flexible_sections',3012);
$frontpage = get_field('flexible_sections',796);
$inserted = $template[1];
array_splice($frontpage,0,0,$inserted );
$field_key = "field_64ca5341d1168";
update_field( $field_key, $frontpage, 796 );
echo "<pre>";
print_r($frontpage);
echo "<pre>";
Although the array insertion occurs it seems its format is not correct and the template section is not recognized in the Frontpage. This is the array print:
Array
(
[0] => layout_section1
[1] => Library: Section 2
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] => Array
(
[acf_fc_layout] => layout_section1
[heading] => Frontpage: Section 1
[image] =>
[layout_name] =>
[position] =>
[subheading] =>
[shortcode] =>
[columns] =>
)
)
Can someone point me the right direction?
Thanks
Jorge
I’m using conditional logic on a taxonomy field (via term IDs) to show/hide additional fields that may/may not be required (based on the taxonomy term selected). No problems here.
The problem I’ve run into, though, is that these term IDs change when they’re created in different environments (local, development, staging and production). And because I’m also using local JSON to store ACF fields, I can’t just update my conditional logic’s term IDs per-environment (as that’s all stored in the JSON files, in GIT, and staging/production don’t have write-access for these files and can only be updated via GIT).
So, wondering if anyone else has run into this issue and if they’ve found a way to deal with this?
Thanks,
Kristin.
I have a case:
I create a custom post type with name is “location” and create taxonomy with name is
district. I use acf create a field radio button in taxonomy district. Then i get_field it, but it return null in spite of value
I am testing a client site on local in preparation to my hosting provider updating to MySQL 8.0. Everything was fine until this message appeared. Please see the error message in the attached image and let me know what it means. I appreciate any help you can provide. I forgot to add my WordPress, ACF and all plugins are up-to-date.
I have created a code to auto send booking emails after a booking status is updated. Depending on the booking status, a certain e-mail text is called. This function works perfectly so feel free to use it 😉
// Send notification emails to guests
function yl_send_booking_email_after_status_update($post_id) {
// Get submitted values.
$values = $_POST['acf'];
// Check if a specific value was updated.
if ( isset($_POST['acf']['field_5fbcef66c1d3f']) ) {
$send_email = $_POST['acf']['field_5fbcef66c1dce'];
$booking_status = $_POST['acf']['field_5fbcef66c1d3f'];
$to = $_POST['acf']['field_5fbcef66c18b8'];
if ( $send_email == 'yes' && $booking_status != 'gesloten' ) {
if ( $booking_status == 'bevestigd' ) {
$subject = get_field('booking_email_subject_confirmed', 'booking_settings');
$message = get_field('booking_email_message_confirmed', 'booking_settings');
} elseif ( $booking_status == 'gewijzigd' ) {
$subject = get_field('booking_email_subject_changed', 'booking_settings');
$message = get_field('booking_email_message_changed', 'booking_settings');
} elseif ( $booking_status == 'geannuleerd' ) {
$subject = get_field('booking_email_subject_canceled_by_guest', 'booking_settings');
$message = get_field('booking_email_message_canceled_by_guest', 'booking_settings');
} elseif ( $booking_status == 'door ons geannuleerd' ) {
$subject = get_field('booking_email_subject_canceled_by_us', 'booking_settings');
$message = get_field('booking_email_message_canceled_by_us', 'booking_settings');
}
$headers = array
(
'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>',
'X-Mailer: PHP/' . phpversion(),
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1'
);
$headers = implode( "\r\n" , $headers );
wp_mail( $to, $subject, $message, $headers );
}
}
}
add_action('acf/save_post', 'yl_send_booking_email_after_status_update', 5);
Now I want to chanllange myself a bit further. I want to auto send (via cron job) a ‘Review request’ email ‘X hours’ after the booking date/time. But I’m stuck for a while now.
Emails do get send but only with pre text. The actuall content of the booking (name, date, time, etc) is left blank.
When I use $post_id in the function, no emails are being send. I hope I made myself a bit clear.
Here’s what I have:
// Send review emails to guests
function yl_send_review_email_function($post_id) {
// Get submitted values.
$values = $_POST['acf'];
$send_email = $_POST['acf']['field_5fbcef66c1dce'];
$booking_status = $_POST['acf']['field_5fbcef66c1d3f'];
$review_delay = get_field('booking_settings_review_delay', 'booking_settings');
$to = '[email protected]';
$subject = get_field('booking_email_subject_review', 'booking_settings');
$message = get_field('booking_email_message_review', 'booking_settings') . '<br /><br />' . $send_email . '<br /><br />' . $booking_status . ' dit no ' . $review_delay;
$headers = array
(
'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>',
'X-Mailer: PHP/' . phpversion(),
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1'
);
$headers = implode( "\r\n" , $headers );
wp_mail( $to, $subject, $message, $headers );
$status = 'gesloten';
update_field( 'booking_status', $status );
}
add_action('acf/save_post', 'yl_send_review_email_function', 5);
// Time schedule for Cron Job Event
function yl_cron_schedules($schedules){
if(!isset($schedules["1min"])){
$schedules["1min"] = array(
'interval' => 1*60,
'display' => __('Once every minute')
);
}
if(!isset($schedules["5min"])){
$schedules["5min"] = array(
'interval' => 5*60,
'display' => __('Once every 5 minutes')
);
}
if(!isset($schedules["30min"])){
$schedules["30min"] = array(
'interval' => 30*60,
'display' => __('Once every 30 minutes')
);
}
return $schedules;
}
// Schedule Cron Job Event
if (!wp_next_scheduled('yl_booking_review_mailer')) {
//You can now use '5min', '20min' or any of the default here
wp_schedule_event( time(), '1min', 'yl_booking_review_mailer' );
}
add_action( 'yl_booking_review_mailer', 'yl_send_review_email_function' );
PS. I left the needed IF STATEMENTS out to be sure that’s nog stopping emails going out.
Hi,
I created a sub-page option to display pictograms in different places on the site.
In this sub-option I created a group with several image fields inside these fields. For each field I checked the array option.
When I add an image it works fine.
On the other hand, when I do not add or delete an image from the field I get an error message that my bool returns false “warning: treating to access array offset on value of type bool”
And this is where I don’t understand why.
On php 7.4 I don’t have any error message, but on php 8 I have this message
<?php
$img = get_field('picto_group','option');
if( !empty ($img)):
// var_dump($img);
?>
<img src="<?php echo $img ['img_button']['url']; ?>" />
<?php endif;?>
update_field('field_5a846b336d34f', $finalArray , $post_id);
$finalArray[]=array(
"field_5a846b336d351"=>"NAME",
"field_5a846b336d353" => "EMAIL",
"field_5a846b336d352" => "TITLE",
"field_5a846b336d354" => "PHONE"
);
So this is the standard way to add rows to a repeater in ACF. It works great on a repeater that is not nested or in a Flexible content block (ACF). The field id in the update_field is the repeaters, who is inside of a Flexible Content Block. This seems to be giving me fits due to it’s location. I have looked at help docs everywhere. If I am calling the repeater by its field ID, why should it matter where it is located in the layouts in ACF? One more note: This repeater is a CLONE but each time I use it as a clone on the site it has it’s own field ID so that shouldn’t give me grief? I am trying to add multiple rows to it at once. Works great on a repeater NOT buried in ACF objects.
I don’t know if this will help or not, but it will give you an idea of where the repeater is located in the ACF page build. Below is what I use to get the output:
while ( have_rows(‘page_builder’,$post_id) ) : the_row();
if( get_row_layout($post_id) == ‘staff_directory’ ): // Staff Directory
if( have_rows(‘directory_type’,$post_id) ):
while ( have_rows(‘directory_type’,$post_id) ) : the_row();
if( get_row_layout($post_id) == ‘directory_table’ ):
if( have_rows(‘staff_member’,$post_id) ):
while ( have_rows(‘staff_member’,$post_id) ) : the_row();
/// THIS IS WHERE I WOULD CALL THE RESULTS OF THE REPEATING INFORMATION ///
endwhile;
endif;
endif;
endwhile;
endif;
endif;
endwhile;
Hey,
I’ve set a ACF named “Category Color” with the following specs (see attach):
– Field Type: Color Picker
– Rules: Taxonomy IS EQUAL TO category
Next, I set #b4151a as the “Category Color” value for a specific category (see attach).
Lastly in Elementor I selected Background -> ACF Color Picker Field -> Category Color (see attach).
Unfortunately there specified color is not reproduced in the frontend.
Any ideas what I’m doing wrong?
Thank you!
How to have a button to download all images from ACF Gallery?
https://capture.dropbox.com/RAbr0gGa2L8Qo0gu
I’ve built an ACF block which allows the user to embed a pre-built acf_form
along with a few options. One of those options is selecting a taxonomy term (service-category) which will determine which services (post type) the end user can choose from in the ‘what service are you enquiring about’ field.
However, I can’t figure out how to filter my acf_form
field to show the services from the chosen taxonomy.
I’ve used acf/load_field
to filter the field args but this appears to be too late in the process and, while the amended arguments appear as I want them, the post_object field returns “The results could not be loaded”.
I’m also filtering acf/fields/post_object/query
but here don’t have access to any of the block (or post) data so can’t amend my query args according to saved meta.
Finally, when logging the query args via acf/fields/post_object/query
I can see that they are unchanged even when using acf/load_field
which causes “The results could not be loaded” – so load_field is having some effect but not the desired one.
Any pointers or ideas for making this work will be gratefully received.
I’m creating a company directory page, where I’m querying all users on he site and displaying their info. Some info is generated from ACF on user profiles. My user loop works great. I’m able to retrieve field data for some of my fields, however, I cannot get the User object field (Manager) to display properly. within ACF, i have this field set to return the User ID. Ultimately I just want the display name of the “Manager”.
WHen trying to return the User Object, instead of the ID, it breaks the site.
Within my user query, I’m using the following:
$args = array('orderby' => 'display_name',);
$users = get_users($args);
foreach($users as $user){
$userID = 'user_'.$user->ID ;
echo '<li>';
echo '<b style="font-size:14px;">' . $user->data->display_name . ' x' . $user->emp_office_ext . '</b><br/>';
echo '<em style="font-size:12px;white-space: nowrap; ">' . get_field('position',$userID) . '</em>';
if (!empty(the_field('manager',$userID))){
$managerID = get_field('manager',$userID);
$managerData = get_userdata($managerID);
$manager = $managerID->display_name;
echo $manager;
}
echo '</li>';
}
I created a new post type called “portfolio”. But when I create new items, there is no option to delete. Even under the list, I have the Edit | Quick Edit | View – but no Trash.
If I use the bulk option, even to try and delete one page, I get the following error:
“Sorry, you are not allowed to move this item to the Trash.”
What is causing this and how can I fix it? Thank you in advance
The post from April of 23 requesting the same thing is marked solved but doesn’t seemed to be solved, or at least there doesn’t seem to be a satisfactory solution for one very common condition…
https://support.advancedcustomfields.com/forums/topic/taxonomy-terms-in-conditional-logic/
I asked about reusing fields in different groups each with different location settings and hube2 pointed me to the idea of using a Taxonomy Field and setting conditional logic with the subsequent fields. It like a very suitable solution.
In that thread, as in the thread posted 3 months ago, hube2 says to use Selection is Greater than [term id-1], and Selection is less than [term id+1]. I found this only works when you have just one term ID selected, which is often not the case, especially when the taxonomy is hierarchical, and both parent and child are selected.
Additionally, as part of this request, it’s worth point out that having to use ‘Greater Than’ and ‘Less Than’ a term ID is not ideal. There are instances in migration where a term id may need to change, but the slug(s) will remain the same.
I have an issue where the_permalink isn’t working when post_object is being used.
<?php the_permalink(); ?>
This should be the post link but is, instead, showing the current page URL on the frontend.
What have I missed?
Can anyone help?
Code below;
<?php
$args = array(
'post_type' => 'cpd',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'asc'
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="cpd-items" class="p25top quiz-results">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="cpd-item quiz-result p25">
<div class="cpd-item-icon">
<i class="fa-light fa-file-lines"></i>
</div>
<div class="cpd-item-content">
<h5><?php the_title(); ?></h5>
<?php $post_object = get_field('quiz_results'); ?>
<?php if( $post_object ): ?>
<?php $post = $post_object; setup_postdata( $post ); ?>
<?php $postid = get_the_ID(); ?>
<?php echo $postid; ?>
<?php wp_reset_postdata( $post ) ; ?>
<?php endif; ?>
<p class="take-quiz-text">You have not yet taken this quiz. Please click the button below.</p>
<p class="p25top retake-quiz-button"><a>">Re-Take the Quiz</a></p>
<p class="p25top take-quiz-button"><a>">Take the Quiz</a></p>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata( $the_query ); ?>
<?php endif; ?>
<?php } else { ?>
<?php } ?>
Hello,
Can anyone help me with pre-populated ACF repeater in innerblock template?
$template = array(
array('core/heading', array(
'level' => 2,
'placeholder' => 'Schrijf de titel',
)),
array('core/paragraph', array(
'placeholder' => 'Schrijf tekst',
)),
This is a repeater field with 3 sub_fields - Link - Color - Icon
array('acf/tf-buttons', array(
)),
Something like this?
array('acf/tf-buttons', array('data' => array('text_field'=> 'Test!'))),
);
global $allowed_jsx_blocks;
echo '<InnerBlocks template="' . esc_attr( wp_json_encode( $template ) ) . '" allowedBlocks="' . esc_attr( wp_json_encode( $allowed_jsx_blocks ) ) . '" />';
I have this problem often and never found a solution to Pre Populate acf repeater fields
I tried this, but doesn’t fill the repeater field:
This is a simpel repeater field with one text field
array('acf/tf-buttons',
array('data' =>
array('test_rep'=>
array('data' =>
array('test_rep_text'=> 'test')
)
)
)
),