Hi there!
In the back-end (not front-end – I can handle this) I want to be able to show groups of fields on the same line in a grid with 3 columns max
I have:
Box Groups (Repeater)
– Box Group (Group)
– Boxes (Repeater)
– Box (Group)
– Title (Text)
– Text Box (Text)
How is this possible please? The image attached was done by tweaking CSS but i feel there must be some settings to use within ACF before I start messing up the backend with CSS fluff!
Cheers all 🙂
I am creating a custom filed type, essentially an extension of the select field type, which will render using select2. IN that it is pretty straightforward, however I wish to load the choices using an ajax query, but I want to keep all the code encapsulated inside the field type, rather than have an additional filter in functions.php to load the choices.
basically I don’t want to have to add anything specific to handle this field outside of the field type itself. So that I can disable the options in the select and have it simply work when dropped into the cms
Hello!
I’m trying to create a bank of multiple choice questions on my site, and I’m brand new to ACF, so was hoping someone could help!
My thoughts were I could create a custom post type called ‘Questions’ and then use field groups to store:
a) Question text
b) Answer options (1-5) as text
c) Which answer is correct
d) Dates/times attempted by the user
e) Whether user answered correctly or not
f) Whether question has been attempted or not
Does anyone have any suggestions on ways to achieve this?
Would be very grateful for any help whatsoever!
I’m working with WooCommerce and Advanced Custom Fields (ACF) in WordPress, and I’ve encountered a peculiar issue when trying to automatically update a custom field (order_shipping_number) in a WooCommerce order. I have two different methods for updating this field when an order’s status changes to “processing”, but only one of them works, and I’m trying to understand why.
Method 1: Direct Update (Not Working) I tried a straightforward approach where I hook directly into the woocommerce_order_status_processing action and update the field using ACF’s update_field function:
add_action( 'woocommerce_order_status_processing', 'update_product_custom_field_', 10, 1 );
function update_product_custom_field_( $order_id ) {
// Generate the shipping number using the order ID
$shipping_number = 'SHIPPINGNUMBERTEST';
// Update the custom field for the shipping number
if (function_exists('update_field')) {
update_field( 'order_shipping_number', $shipping_number, $order_id );
}
}
This method seems logical, but it doesn’t update the field in the WooCommerce order.
Method 2: Using acf/save_post (Working) However, when I use a nested action hook with acf/save_post, it works:
add_action( 'woocommerce_order_status_processing', 'update_product_custom_field_');
function update_product_custom_field_( $order_id ) {
add_action('acf/save_post', 'update_shipping_number');
}
function update_shipping_number( $order_id ) {
$shipping_number = 'SHIPPINGNUMBERTEST';
update_field( 'order_shipping_number', $shipping_number, $order_id );
}
With this method, the field updates as expected.
My Question: Why does the second method using acf/save_post work, but the direct approach fails to update the field? Is there something specific about how ACF handles data saving in the context of WooCommerce orders that requires the acf/save_post hook?
Any insights or explanations would be greatly appreciated, as I’m trying to understand the underlying mechanics of ACF and WooCommerce interactions.
I’m building a quoting system and need to populate a custom text field (quote_number) with the post id when the new post is created. I can’t just use the post_id when displaying the post as I have a previous quoting website built with Toolset Types that have existing id’s that filled the quote number field.
I tried the code from this post: https://support.advancedcustomfields.com/forums/topic/automatically-populate-custom-field-with-post-id/
function acf_load_field_choices( $field ) {
// Create an empty array
$field[‘choices’] = array();
// Populate field with the current post id
$field[‘choices’][0] = get_the_ID();
// Return the result
return $field;
}
add_filter(‘acf/load_field/name=test’, ‘acf_load_field_choices’);
There was no explanation as to how they got it right.
The post type is ‘quote’ and the field to be populated is quote_number.
Can someone explain the code above and how to modify it for my site.
Thanks
Following this documentation, I created a frontend form that, on submission, creates a post and sends an email notification.
The thing is, while the field group is located on the main subsite (ID:1) of a multisite network, I actually want to display the form on several subsites.
I managed to display the form with no problem with switch_to_blog();
switch_to_blog(1);
$today = date("Y-m-d-H-i-s");
$args = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'enquiry',
'post_status' => 'publish',
'post_title' => $today
),
'field_groups' => array(3496),
);
acf_form($args);
restore_current_blog();
add_action('acf/save_post', 'create_post_from_form_v2');
function create_post_from_form_v2($post_id) {
...
}
However, since the field group (nor the CPT) doesn’t exist on the secondary subsites, the post creation and email notification do not work.
Is there any way to create the new post on a specific subsite?
Or, is it possible to get the values of the submitted form without actually creating a post? I would then use insert_new_post() to create the post and send the email.
I know that an alternative could be to create the CPT on the secondary subsites and synchronize the field group on all the subsites so as the new post is created on the current subsite, but I would like to avoid that.
In ACF Pro you can add fields to nav menu items. I have discovered that the image field doesn’t work in Chrome. Nothing happens when you click the “Add Image” button. I believe this is a bug.
I’ve built a handy ‘contact form’ block for my client via which they can choose from several baked in form variations, as well as button text, colour, etc, all of which render beautifully in the block editor so they know what they’re getting.
However, some of my acf_form fields are mandatory and fail validation when the post or page is saved. I originally got around this by using acf/load_field
(see below) to remove validation if being viewed in the block editor (is_admin()
) and while that does solve the admin issue it’s causing problems with the Ajax validation on the front end so that when my consent checkbox fails, instead of showing the little warning it loads a new error page saying “validation failed”.
if( is_admin() && 'acf-field-group' !== get_post_type() ):
$field['required'] = false;
endif;
return $field;
Is there a better method for preventing or turning off field validation just when an acf_form is being rendered in the block editor?
I found the same question being asked of ACF Extended but their solution was to prevent block editor rendering of the form entirely which would really detract from the usefulness of this block.
Any recommendations will be very grateful received.
We are using ACF Pro / Paid Plugin.
We have added a custom field on all our products – the field being the ‘File Upload’.
Can anyone assist with the following, or even, advise if this is something simply out of touch or better worded, just not possible
When the user uploads a file on product post #1 , example ‘image-1.jpg’ , this being the first instance they would be charged e.g. $1.00.
If the user decides to upload a file on another product post e.g. #2, if the filename is the same e.g. ‘image-1.jpg’ they will not be charged $1.00 as the image has been uploaded.
I understand this may cause issues in the event more than one user uploads a file with the same filename. So, secondly, is their a solution to this somehow to prevent a customer not being charged when they should be?
OR
Can we possibly do a unique count of files uploaded in one’s basket where the user has selected on products “file not uploaded before” and for each count charge $1.00
Example
Product 1 – user has selected logo uploaded before – ignore this file
product 2 – user has selected not uploaded logo before – filename1.jpg
product 3 – user has selected not uploaded logo before – filename1.jpg
product 4 – user has selected not uploaded logo before – filename2.jpg
Count = 2 (2 unique files uploaded) , charge = $2.00
Is it worth noting, customers are not enforced to be logged in (WooCommerce).
Our vision may not be the best way, and their maybe a better way to achieve the desired goal above.
Kind Regards,
Hi.
I have been working on creating a select field in Advanced Custom Fields (ACF) where the choices are dynamically populated based on a textarea input in a fixed page. I followed the guide on “Populating Choices From a Repeater Field” from the ACF documentation here: [https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/](https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/).
In the textarea, I’m inputting choices in the following format:
`
value_abc : LABEL_ABC
value_xyz : LABEL_ZETTN
`
When I edit the textarea to add choices, the labels appear correctly in the post edit screen and are selectable.
However, when the post is published and I use get_field()
to display the data, it shows the value instead of the label. This is not the expected behavior, as I would prefer the label to be displayed.
Could you advise on what might be missing or required in the theme or ACF settings to correctly display the label instead of the value?
As an additional note, after some trial and error, I found that exporting and then re-importing ACF settings seemed to correct the issue and the labels displayed as expected. I hope this information might be helpful in diagnosing the issue.
Thank you for your assistance.
when i use php export code for import acf noting be imported for me
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_640fb15bd3fa4',
'title' => 'SEO',
'fields' => array(
array(
'key' => 'field_640fb15c6b2db',
'label' => 'SEO TITLE',
'name' => 'seo_title',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
));
'menu_order' => 0,
'position' => 'side',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
'show_in_rest' => 0,
) );
} );
Hello
I have two custom post types (kurse, infoabend) with ACF date fields. The query of these posts sorted by date works fine.
$today = date ('Ymd');
$args = array(
'post_type' => array( 'kurse', 'infoabend' ),
'post_status' => array( 'publish', 'future' ),
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'meta_query' => array(
'relation' => 'OR',
'kurs_clause' => array(
'key' => 'kurs_kursdaten_0_datum',
'compare' => '>=',
'value' => $today,
),
'infoabend_clause' => array(
'key' => 'datum',
'compare' => '>=',
'value' => $today,
),
),
'orderby' => array(
'kurs_clause' => $order,
'infoabend_clause' => $order,
),
);
I added ACF fields to the search and limited search to these two post types. To be able to sort the search results by date, I added the meta query I used in the first query.
add_action( 'pre_get_posts', __NAMESPACE__ . '\\d_edit_wp_query' );
function d_edit_wp_query( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search ) {
if( !empty( $query->query['orderby'] ) && 'date' === $query->query['orderby'] {
$current_meta = ( empty ( $query->get('meta_query' ) ) )
? []
: $query->get( 'meta_query' );
$today = date ('Ymd');
$custom_meta = [
'relation' => 'OR',
'kurs_clause' => array(
'key' => 'kurs_kursdaten_0_datum',
'compare' => '>=',
'value' => $today,
'meta_type' => 'DATE',
),
'infoabend_clause' => array(
'key' => 'datum',
'compare' => '>=',
'value' => $today,
'meta_type' => 'DATE',
),
'orderby' => array(
'kurs_clause' => $query->query['order'],
'infoabend_clause' => $query->query['order'],
)
];
$meta_query = $current_meta[] = $custom_meta;
}
}
}
Unfortunately, the sorting by date does not work correctly. I would be grateful for any tips and ideas on how to solve the problem.
Hi,
I have thousands of pages, mixed between classic content, hotels data, etc…
I’m actually working on a script that :
1. export pages with a search query to get all hotels -> ok
2. import these content in my custom post type hotels -> 99% ok
My editors actually use Elementor Google maps widget, with filling location with name of the hotel.
I need to import this to ACF.
And I need to be able to extract country of the hotels during the import.
So I first tried to use ACF google maps field, with filling it with the name of the hotel, as on Elementor Widget. But it doesn’t work, because Google maps ACF field is waiting for JSON data.
So I tried to query google maps API to get JSON, and it partialy works. For some hotels, it’s ok. But for some hotels, it doesn’t find it. While on Elementor GM widget, it find it.
If I use GM ACF field, and manually create a new post, when I add the name of this hotel, it didn’t find it at all.
Do you have any idea to help me get rid of this issue ?
I have the following code for functions.php working for the post archives belonging to the whole taxes. It sorts their archive pages by date set in ACF field ‘release-date’.
add_action( 'pre_get_posts', 'customize_game_tag_archive_query', 10 );
function customize_game_tag_archive_query( $query ) {
if ( $query->is_tax( array ('time', 'game_status', 'genre', 'publisher', 'developer', 'platform', 'gameplay') ) ) {
// Sort posts by ACF release date.
$query->set( 'order', 'DESC' );
$query->set( 'orderby', 'meta_value_num' );
// ACF date field value is stored like 20220328 (YYYYMMDD).
$query->set( 'meta_key', 'release-date' );
}
}
It works fine, but I have a term ‘early-access’ inside ‘game_status’ tax and I need its archive to be sorted by another ACF date field named early-access-release-date
. How can I achieve this?
I created 2 CPT:
Company
Documents
I created a Relationship field, so that I can associate the documents to the company.
I have a single post template for my Company. I am using a Bricks Query Loop referencing the relationship field to display the corresponding documents on the single post template. How can I order my documents based on a custom field? In this case the Publication date of the document.
Hi,
I’m attempting to create a query to find any Case Studies (a Custom Post Type) that are selected via the page. This is my first time using the Taxonomy field, and although it works, I get the error in Debug mode “Warning: Invalid argument supplied for foreach() in…”. I’ve followed a few suggestions to fix that, but they don’t show any results.
My Field Page
<img src="https://postimg.cc/D4GNVRYQ" alt="" />
My Code
<?php
foreach($case_study_category as $cs) { $cs = get_category($cs); }
$args = array(
'post_type' => 'case-study',
'posts_per_page' => 9,
'post_status' => 'publish',
'orderby' => 'publish_date',
'category__in' => array($case_study_category),
);
$study_query = new WP_Query( $args);
if ( $study_query->have_posts() ) {
?>
<div class="post-grid post-grid--scroll-mob">
<?php
while ( $study_query->have_posts() ) {
$study_query->the_post();
$name_title = get_field('name_title');
?>
<a>" class="post-block f-rounded-bottom-lg mob-center-fix">
<?php if(has_post_thumbnail()) {
the_post_thumbnail('case-study', array('class' => 'post-image post-image--featured', 'alt' => $name_title));
} else {
?>
<img src="https://placehold.co/1232x924" />
<?php } ?>
<span class="post-block__text box-pad-xs d-block">
<h5 class="font-inter color-black weight-600 text-scale-sm mb-0"><?php echo the_title(); ?></h5>
<?php if( ($name_title) ) : ?><h6 class="post-sub-title font-quicksand color-blue text-uppercase weight-600 mb-0 text-scale-mini"><?php echo $name_title; ?></h6>
</span><?php endif; ?>
</a>
<?php
}
?>
</div>
<?php
wp_reset_postdata();
} else {
?>
<p class="color-brown">There are currently no Case Studies to show associated with this service.</p>
<?php
}
?>
I have a custom post type that I’d like to group in years (in an accordion display) by using the ACF date field. I use the following date format in my ACF and WP settings d/m/Y.
Somehow some posts don’t end up in the correct year but in 1970. How to make sure the date formatting is working as expected?
<?php
// Retrieve the list of posts from your CPT 'accreditations' with ACF fields 'description' and 'date'
$posts = get_posts(array(
'post_type' => 'accreditaties',
'posts_per_page' => -1,
)); ?>
<?php
// Sort the posts by the 'date' field in descending order
usort($posts, function($a, $b) {
$dateA = get_field('acc_aanvangsdatum', $a->ID);
$dateB = get_field('acc_aanvangsdatum', $b->ID);
return strtotime($dateB) - strtotime($dateA);
});
// Create an associative array to group posts by year
$groupedPosts = array();
// Iterate through the sorted list of posts and assign each post to the corresponding year
foreach ($posts as $post) {
$date = get_field('acc_aanvangsdatum', $post->ID);
$year = date('Y', strtotime($date));
if (!isset($groupedPosts[$year])) {
$groupedPosts[$year] = array();
}
$groupedPosts[$year][] = $post;
}
// Iterate through the grouped posts and generate the HTML markup for each year's section
foreach ($groupedPosts as $year => $posts) {
echo '<button class="accordion"><h4>' . $year . '</h4></button>';
echo '<div class="panel accreditaties">';
?>
<div class="grid-container">
<div class="grid-item" id="grid-item-title"><p>Aanvangsdatum</p></div>
<div class="grid-item" id="grid-item-title"><p>Titel</p></div>
<div class="grid-item" id="grid-item-title"><p>Status</p></div>
<div class="grid-item" id="grid-item-title"><p align="right">Uren</p></div>
<?php
// Sort the posts within each year section by date in descending order
usort($posts, function($a, $b) {
$dateA = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $a->ID));
$dateB = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $b->ID));
return $dateB <=> $dateA;
});
foreach ($posts as $post) {
$title = get_the_title($post->ID);
$acc_aanvangsdatum = get_field('acc_aanvangsdatum', $post->ID);
$acc_status = get_field('acc_status', $post->ID);
$acc_uren = get_field('acc_uren', $post->ID);
$acc_beschrijving = get_field('acc_beschrijving', $post->ID);
?>
<div class="grid-item"><p><?php echo $acc_aanvangsdatum ?></p></div>
<div class="grid-item"><p><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $title ?></a></p></div>
<div class="grid-items-status-uren">
<div class="grid-item status"><p><?php echo $acc_status ?></p></div>
<div class="grid-item uren"><p align="right"><?php echo $acc_uren ?></p></div>
</div>
<?php
}
echo '</div>'; // Move the closing </grid-containe> tag here
echo '</div>';
}
?><br>
<script>
var years = document.getElementsByClassName("year");
var i;
for (i = 0; i < years.length; i++) {
years[i].addEventListener("click", function() {
var posts = this.nextElementSibling;
if (posts.style.display === "block") {
posts.style.display = "none";
} else {
posts.style.display = "block";
}
});
}
</script>
For a holiday home website (for context) – I’ve created a few Gutenberg blocks using ACF – such as a gallery slider.
I now have a Gutenberg block called ‘Property Previews’ which is a Relationship field. The idea being the user can insert a block called Property Previews, select which properties they want to display on that page, and it’ll show content from that Property page.
The issue I’m having is returning the ACF fields from the Gallery slider, within the Relationship field. I got as far as this, but this just retuns every single content block from the Property page, instead of just the hero slider. I also only want to return the image field from the Gallery Slider, instead of the whole block as I need to customise the slider. Any help?
<?php
$previews = get_field('select_property');
if( $previews ): ?>
<div class="property-previews">
<?php foreach( $previews as $preview ):
$permalink = get_permalink( $preview->ID );
$title = get_the_title( $preview->ID );
?>
<article class="property-previews__card">
<a>"><h2><?php echo esc_html( $title ); ?></h2></a>
<?php
if ( has_blocks( $preview->post_content ) ) {
$blocks = parse_blocks( $preview->post_content );
foreach ($blocks as $block) {
if ($block['blockName'] === 'acf/hero-gallery-slider');
echo render_block($block);
}
} ;
?>
</article>
<?php endforeach; ?>
</div>
<?php endif; ?>
This is what my Gallery Slider code looks like:
<?php
$images = get_field('hero_gallery_slider');
if( $images ): ?>
<div class="hero-gallery-slider-main">
<div class="slider-for">
<?php foreach( $images as $image ): ?>
<div>
<div class="hero-gallery-slider-main__image">
<img />" alt="<?php echo esc_attr($image['alt']); ?>" height="<?php echo esc_attr($image['height']); ?>" />
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
Hi good day,
Hi I add 2 additional fields for users,
mag_date_of_birth
mag_age
Now i try to update the age of all user based on the date of birth thru sql command and here is my command,
UPDATE wp_usermeta AS m1
JOIN wp_usermeta AS m2 ON m1.user_id = m2.user_id
SET m1.meta_value = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), m2.meta_value)), '%Y') + 0
WHERE m1.meta_key = 'mag_age'
AND m2.meta_key = 'mag_date_of_birth'
now my problem here is when I execute that command it returns and error said “Incorrect datetime value”
mag_date_of_birth field is datepicker
where it saves data on database like this “19911207”
I think 19911207 and 1991-12-07 is different…
can anyone correct my sql command please…
screenshots
https://imgur.com/a/Gv2uxVx
Hello ACF team and users,
I am working with ACF Pro for a very long time, and today I want to create a dynamic planning/agenda with ACF and the JS API, on a web project (nginx / PHP 7 / WordPress 6.4).
I have multiples ACF forms loaded on my front-end page, and based on the action want
-add post
-edit post
I reload each form via a ajax call and a WP hook.
function flweb_return_add_tour(){
acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'tours',
'post_status' => 'publish'
),
));
}
add_action('wp_ajax_flweb_return_add_tour', 'flweb_return_add_tour'); // for logged in user
$.ajax({
method: "POST",
url: self.$ajaxurl,
data: {
action: 'flweb_return_add_tour',
date: self.$date,
postid: id
}
})
.done(function (msg) {
//remove the old form
elem.children('.box-system-box').find('#acf-form').remove();
//insert new one
elem.children('.box-system-box').append(msg);
//reload acf fields
acf.do_action('append', $('#bar-add-cmd'));
});
Is this way the good way ?
I am wondering if there is another JS way to load the data inside the form via the API. Knowing that I have multiples forms on the same page.
Thanks for reading me,
Lola
Hallo zusammen,
ich versuche im WordPress-Backend eine acf_form zu laden, die jedoch in einem MODAL angezeigt wird. Sprich ich habe ein Button gemacht – und wenn ich den Klicke öffnet sich ein MODAL Fenster.
Das klappt auch soweit.. Textfelder kann ich bearbeiten und speichern. Aber der Bilder-Upload funktioniert nicht.. hat jemand eine idee?
Hier mal der Code:
function create_acf_form() {
ob_start();
wp_localize_script( 'my-ajax-script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_media();
acf_enqueue_scripts();
acf_form_head();
$post_id = id_finder();
if (!$post_id) {
return 'Kein Post gefunden.';
}
$field_group_name = 'group_655c9ef91419b';
$field_group = acf_get_field_group($field_group_name);
$options = array(
'field_groups' => array($field_group['ID']),
'post_id' => $post_id,
'submit_value' => __('Speichern', 'test-projekt'),
'return' => '/wp-admin/post.php?post=' . $post_id . '&action=edit&classic-editor',
);
acf_form($options);
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
Damit erstelle ich die FORM und mit <?php echo create_acf_form(); ?> lade ich die form dann im modal..
Freue mich über ideen! 😀
I need customize restapi. I have function for filtering image data:
function jk_acf_restapi_filtering_image_format($value, $post_id, $field) {
// Ensure that the ACF image field value is valid and represents an existing attachment
if (empty($value) || !wp_attachment_is_image($value)) {
return false; // Return false or an empty array if the value is invalid
}
// Get the full image object from the ID using wp_get_attachment_image_src()
$image = wp_get_attachment_image_src($value, 'full');
// Ensure that the image exists
if (!$image || is_wp_error($image)) {
return false; // Return false or an empty array if the image doesn't exist
}
// Get the attachment post object using get_post()
$attachment = get_post($value);
// Store the base URL of your WordPress site
$base_url = get_home_url();
// Create an array to store the image data with "sizes" key
$data = array(
'url' => str_replace($base_url . '/wp-content/uploads/', '', $image[0]),
'sizes' => array(),
);
// Add the alt text and title
$data['alt'] = get_post_meta($value, '_wp_attachment_image_alt', true);
$data['title'] = $attachment->post_title;
// Loop through each available image size
$metadata = wp_get_attachment_metadata($value);
if (!empty($metadata['sizes'])) {
foreach ($metadata['sizes'] as $size => $details) {
// Get the image URL for the current size using wp_get_attachment_image_src()
$image_src = wp_get_attachment_image_src($value, $size);
// Ensure that the image URL exists for the current size
if ($image_src && !is_wp_error($image_src)) {
// Remove the base URL and '/wp-content/uploads/' path from the image URL
$url = str_replace($base_url . '/wp-content/uploads/', '', $image_src[0]);
// Add the image URL and dimensions to the "sizes" array
$data['sizes'][$size] = array(
'url' => $url,
'width' => $image_src[1],
'height' => $image_src[2],
);
}
}
}
// Return the image data array
return $data;
}
It works with:
add_filter('acf/rest/format_value_for_rest/type=image', 'jk_acf_restapi_filtering_image_format', 10, 3);
But i need use:
add_filter('acf/format_value/type=image', 'jk_acf_restapi_filtering_image_format', 10, 3);, the response of image is false.
I have custom endpoint, so i must use format_value.
Does format_value need any special return format?
I’ve created an ACF taxonomy field that should show my categories inside my custom taxonomy. This taxonomy contains categories and has connected posts. Normally the field should show all the categories, but now it wont. Instead it first loads and after that it gives the error ‘Laden mislukt’ which is dutch for something like ‘Loading Failed’. Does someone know what could be the reason the field won’t load anymore? Beside a font issue we dont have specific errors in the console or php-errors when activating the debug.
Code for registering the custom post type and taxonomy
function cpt_kennisartikel() {
$labels = array(
'name' => _x( 'Kennisartikelen', 'i2sa'),
'singular_name' => _x( 'Kennisartikel', 'i2sa'),
'menu_name' => _x( 'Kennisartikelen', 'i2sa'),
'name_admin_bar' => _x( 'Kennisartikelen', 'i2sa'),
'add_new' => _x( 'New item', 'i2sa'),
'add_new_item' => __( 'Add new item', 'i2sa'),
'new_item' => __( 'New item', 'i2sa'),
'edit_item' => __( 'Edit item', 'i2sa'),
'view_item' => __( 'View item', 'i2sa'),
'all_items' => __( "All items", 'i2sa'),
'search_items' => __( 'Search item', 'i2sa'),
'parent_item_colon' => __( 'Parent item:', 'i2sa'),
'not_found' => __( 'Search query not found.', 'i2sa'),
'not_found_in_trash' => __( 'Search query not found.', 'i2sa')
);
$args = array(
'labels' => $labels,
'description' => "Beschrijving i2sa",
'public' => true, //openbaar
'exclude_from_search'=> false, //uitschakelen voor zoekopdrachten
'publicly_queryable' => true, //publiekelijk vindbaar
'show_in_nav_menus' => false, //toon in navigatie
'menu_icon' => 'dashicons-lightbulb',
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'kb' ), //custom url
'capability_type' => 'post',
'has_archive' => false, //heeft archivepage
'hierarchical' => false, // true maakt het een pagina
'menu_position' => 5, //null = geen
'supports' => array('editor', 'title', 'thumbnail'), //gesupporte functionaliteiten
);
register_post_type( 'kennisartikel', $args );
//flush_rewrite_rules();
}
add_action( 'init', 'cpt_kennisartikel' );
function cstm_taxonomy_kb() {
$post_types = array('kennisartikel');
$taxonomy_args = array(
'label' => 'Artikel Categorie (KB)',
'rewrite' => array('slug' => 'tax-kb'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'has_archive' => false,
);
foreach ($post_types as $post_type) {
register_taxonomy('cc_tax_kb', $post_type, $taxonomy_args);
}
}
add_action('init', 'cstm_taxonomy_kb');
Setup of the field and error attached as screenshot.
Hello. I have a few ACF blocks an 3 of them use the swiper slider. Now I have the problem that swiper-bundle.min.js loads 3 times when I used all 3 blocks on a page. How can I prevent this? Here is a block.json from one of the blocks.
{
"$schema": "https://advancedcustomfields.com/schemas/json/main/block.json",
"name": "home-slider",
"title": "Slider",
"description": "Slider für die Startseite",
"category": "cdh",
"icon": "star-filled",
"keywords": ["slider", ""],
"styles": [],
"acf": {
"mode": "preview",
"renderTemplate": "home-slider.php"
},
"supports": {
"align": false,
"anchor": true
},
"editorStyle": "file:./style/home-slider-editor.css",
"script": ["file:./home-slider.js", "file:./swiper-bundle.min.js"],
"editorScript": "file:./home-slider.js",
"viewScript": ["file:./home-slider.js", "file:./swiper-bundle.min.js"],
"style": ["file:./style/home-slider.css","file:./style/swiper-bundle.min.css" ]
}
Heres the block.asset.php
<?php
return array(
'dependencies' => array(
'jquery',
'swiper',
),
'version' => '1.0.0',
);
I want the required scripts for the blocks to only be loaded if it hasn’t been loaded yet.
I made an event system with a custom-post. I use ACF classic.
I therefore display my posts only if they are equal to today’s date or in the future. All old posts are therefore hidden. This all works very well.
Problem is that when the year is 2024, everything beyond December 31, 2023 is considered old… I know this because when I change my value from ($date_event >= $today)
to ($date_event <= $today)
it displays it to me in my old posts..
I don’t understand..
<?php
$loop = new WP_Query( array( 'post_type' => 'evenement', 'posts_per_page' => 10, 'meta_key' => 'start_event', 'orderby' => 'meta_value', 'order' => 'ASC' ) );
while ( $loop->have_posts() ) : $loop->the_post();
$today = date("m-d-Y");
$date_event = get_field('start_event');
?>
<?php if ($date_event >= $today) { ?>
<?php
$date = DateTime::createFromFormat( 'm-d-Y', $date_event );
$date_format = $date->format( 'j F Y' );
$date_rendu = date_i18n("j F Y", strtotime($date_format));
?>
<a href="<?php echo get_permalink() ?>">
<div class="image">
<?php echo the_post_thumbnail(); ?>
</div>
<div class="description">
<div class="dates">
<?php echo $date_rendu ?>
</div>
<div class="nom">
<?php echo the_title(); ?>
</div>
</div>
</a>
<?php }; ?>
<?php endwhile; ?>