Hey all,
I’ve submitted an issue via Github but haven’t had a response, so hoping that someone could help here?
https://github.com/AdvancedCustomFields/acf/issues/908
Questions (Repeater)
— Question (Text)
—- Answers (Repeater)
—— Answer (Text)
——– Questions (Clone Questions)
As above, I have a repeater which has a nested repeater, that includes a Clone field to allow the user to create as many iterations as they wish.
Unfortunately, it appears that the cloned Questions repeater will only show for the first level of Answers.
If you add a question, it will show all of the other cloned fields but not the repeater.
Not sure if this is a known limitation, or a bug so would appreciate any of your thoughts.
I am using ACF as a headless cms for my angular website i’m building.
Currently I have a post type called News and i am fetching them all at once.
However I would like to fetch only a handful of them with pagination enabled.
I have tried adding posts_per_page in the query params and offset and none work, instead i get all posts.
How can i fetch only a certain number of posts and enable pagination ? ( Using HttpClient module )
Hello! I run a concert website. We have a post type for artists , recent press and concerts, which are bidirectionally related with an ACF relationship field. In the press admin, I would love to be able to filter posts by artist. Currently, if I click the artist name, it links to the associated artist page, which is fine. But then there is no way to filter posts. Any help would me much appreciated 🙂
Hi,
I would like to extend the “Page Link” field type so that when “Allow Archive URLs” is ticked, category archives are also returned. In order to do this I would need to be able to filter the results array in ajax_query()
in class-acf-field-page_link.php
.
I believe this would be a useful feature for a number of users and use cases, across all field types that use AJAX search.
Thanks!
Hey @support,
I need to know that when I am rendering this custom code it display the same content on different post I need to see different content. How can I do that.
if ($blog_query->have_posts()) :
while ($blog_query->have_posts()) :
$blog_query->the_post();
if (have_rows(‘work-sections’))
while (have_rows(‘work-sections’)) : the_row();
$current_post_id = get_the_ID();
if (get_row_layout() == ‘layout_1’) :
include(dirname(__FILE__) . “/flexible-content/sections/image-layout.php”);;
elseif (get_row_layout() == ‘layout_2’) :
include(dirname(__FILE__) . “/flexible-content/sections/headng-content.php”);
elseif (get_row_layout() == ‘testemonial_layout’) :
include(dirname(__FILE__) . “/flexible-content/sections/testemonial-content.php”);
elseif (get_row_layout() == ‘video_layout’) :
include(dirname(__FILE__) . “/flexible-content/sections/video-section.php”);
endif;
endwhile;
endwhile;
else :
// echo ‘No post found’;
endif; ?>
Hi,
I’m currently working on an icon selector, that basically open a modal containing several icon you can pick. In order to do so, I created a custom field type for ACF with an input with the type “hidden”, following these steps.
Basically I use a script that opens a modal if you click on the icon preview of the field, and you can pick an icon from here. When you click on one, it closes the modal, and update both the icon preview’s src
and the hidden input field’s value
.
I also created a custom block with ACF too, and assign a fields group to make it contain my custom icon-selector field type, including a title (simple ACF text field).
Everything works fine as it is, but only the first time you select an icon.
After that, in despite of the input value being updated, WordPress doesn’t seem to trigger an event saying “hey, the field’s value has changed, I need to update it on post save”.
What exactly happens behind the scenes sounds quite mysterious for me but is my guess because, if you change the other field of the block in the meantime (the title), then it considers the block fields have changed, and also save correctly the icon modification.
Hence my question: is there a way to force WordPress to consider that the block updated when the field’s value changed with JS?
Thank you in advance.
Hello,
I used to use ACF to get data about articles, according to the type of article.
For example, I have a series of fields for BRAND items, then fields for PRODUCT items.
Everything’s fine.
I was wondering if it’s possible to query from one to the other.
Let me explain 🙂
To display my PRODUCTS on the BRAND page, it’s quite simple, it’s just a list of items with a query based on a category.
But how do you do the opposite?
What I’d like is for my PRODUCT page to be able to retrieve data from my BRAND page.
In other words, in my template, for example, on the left I’d have the information (and ACFs) for my PRODUCT, and on the right, the information for the BRAND, according to the PRODUCT.
For example: if PRODUCT = 1, then I display BRAND1 DATA1, BRAND1 DATA2
and so on.
I imagine I’m not the first to have this problem, and I understand it’s the subject of repeater, but I don’t quite understand 🙂
At this stage I don’t have the PRO but if that’s what I’m looking for, I’ll obviously buy the license.
Thx
Best
I am currently using this code for my event page:
function dd_query_by_event_date( $query ) {
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'start_date' );
$query->set( 'meta_query', array(
array(
'key' => 'start_date',
'value' => date( 'Y-m-d' ),
'compare' => '>=',
'type' => 'DATETIME',
),
) );
}
add_action( 'elementor/query/dd_event_date', 'dd_query_by_event_date' );
and then load this via the query at Elementor Pro so that the grid is sorted accordingly. However, the above script also removes all multi-day events on the starting day
I also saw this on this forum:
https://support.advancedcustomfields.com/forums/topic/sorting-using-acf-date-field/#post-170900
However, I cannot get this to work, I think this has to do with the fact that this code is built on the basis of a page and not on the basis of a function script
Who can help me with this ?
Not sure if this should be reported here or in the wordpress trac – but maybe someone had similar issue and found proper solution for it.
For sure it’s related with the WordPress core file.
After adding ‘wysiwyg’ field to the attachment modal – it’ll trigger ajax call on every single change – this will flood the database with the requests and create lots of unneeded data in _postmeta
table.
Hi, i would like to sort all posts according to the date of my start_time meta field. But no matter what i try i always get Nothing Found. Also had no luck when i try get_posts or a WP_Query.
What am i doing wrong?
Here’s the code:
function mind_pre_get_posts( $query ) {
if( is_admin() ) {
return $query;
}
if( $query->is_main_query() ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'start_time');
$query->set('order', 'DESC');
}
return $query;
}
add_action('pre_get_posts', 'mind_pre_get_posts');
And here’s the custom field group:
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'Meta info',
'fields' => array (
array (
'key' => 'start_time',
'label' => 'Exhibition start',
'name' => 'exhibition_start',
'type' => 'date_picker',
),
array (
'key' => 'end_time',
'label' => 'Exhibition end',
'name' => 'exhibition_end',
'type' => 'date_picker',
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));
I sthere a way to use an ACF block template that outputs to InnerBlocks inside a Block Theme template?
Even when I put the InnerBlocks output inside a php echo, the actual output seems to be pre-rendered in the template file, not picking up the meta data of the post that uses the template.
It’s quite frustrating, as anything else using PHP (echo $value or even print_r($inner_blocks_template) shows all the correct data.
Img 1 = print_r($inner_blocks_template)
in block inside single post template
Img 2 = <?php echo '<InnerBlocks
in block inside single post template
class="bs-exhibdate-block-acf__innerblocks"
template="' . esc_attr( wp_json_encode( $bsdates_inner_blocks_template ) ) . '"
/>'; ?>
Only way I’ve gotten it to work is with echo do_block, wich is even more cumbersome to use than InnerBlocks:
<?php echo do_blocks('<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20","left":"var:preset|spacing|20","right":"var:preset|spacing|20"},"margin":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20"},"blockGap":"var:preset|spacing|20"}},"className":"exhibdates","layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group exhibdates" style="margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)"><!-- wp:paragraph -->
<p>' . $exhibstart . '</p>
<!-- /wp:paragraph --> (etc)
Am I missing something simple, or is that just how this InnerBlocks stuff works?
Hi, is this the proper way to obfuscate an email address?
<a href="mailto:<?php antispambot( the_field('email') ); ?>"><?php antispambot ( the_field('email') ); ?></a>
When I run that I don’t get anything broken but am not able to see in the source client side that anything is obfuscated.
Been waiting for years for this, but now I don’t seem to understand how to use it:
ACF 6.3 Beta 1 (apparently) has the ability to save meta fields into the database from an ACF block.
However, I have not been able to get it to work, and I’m now trying to understand what “This functionality would enable you to create a custom post type, with a locked block template, letting you replicate a classic editor-like experience where only your block exists to enter specific structured data. This data would then be stored in post meta and allow you to query it easily.” means. It does sound more restricting than what I was hoping for.
Looking forward to some examples 🙂
Hi, I’m trying to add a simple category filter to add to an ACF field. I would need to filter the search results, restricting it to only two specific categories for selection. I use this code in functions.php
thanks
add_filter('acf/fields/taxonomy/query/name={$cat_f}', 'my_acf_fields_taxonomy_query', 10, 3); //
function my_acf_fields_taxonomy_query( $args, $field, $post_id ) {
// Show 2 terms per AJAX call.
$args['name'] = 'cat1, cat2';
return $args;
}
Hello guys !
I’m following this tutorial and I try to apply it to my website.
https://www.advancedcustomfields.com/resources/querying-relationship-fields/
I have artists thats plays in places.
An artist can play in different places, so i want to compare the row of the repeater field with the current place ID. And only show the row where the place is the same that the page.
But i don’t know how to achieve it…
Anyone can help me ?
Thanks
Here is the code for the place : single-place.php
<?php
function allow_wildcards( $where ) {global $wpdb;
$where = str_replace("meta_key = "representation_%", "meta_key LIKE }representation_%",
$wpdb->remove_placeholder_escape($where)
);return $where;}
add_filter('posts_where', 'allow_wildcards');
?>
<?php
$query = new WP_Query(array('post_type' => 'artiste',
'meta_query' => array(
array(
'meta_key' => 'representation_%_lieu_representation',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
)
)
));
?>
<?php if($query->have_posts()) : while ($query->have_posts() ) : $query->the_post();?>
<?php if( have_rows('representation') ): while( have_rows('representation') ) : the_row();?>
<p>
<?php $date_rep = get_sub_field('date_representation');?>
<?php echo $date_rep; ?> <?php the_title();?>
</p>
<?php endwhile; else : endif; ?>
<?php endwhile; else: endif; wp_reset_postdata();?>
Hi,
I am trying to extend searching capabilities in acf Post Object field, where one can chose podcasts . He needs to be able to search these podcasts with extra title created with acf text field.
Just to mention that this post object is in flexible content repeater.
Here is my code that should work but it doesn’t, any idea ?
add_filter('acf/fields/relationship/query/name=podcasts_obj', 'my_custom_relationship_query', 10, 3);
function my_custom_relationship_query($args, $field, $post_id) {
// Limit the filed i want to extend
if ($field['name'] == 'podcasts_obj') {
// Searched extra title
$podcast_sub_title_field_name = 'podcast_sub_title';
// Default settings
$search_term = isset($_POST['search_term']) ? $_POST['search_term'] : '';
// Add meta_query with podcast_sub_title field
$args['meta_query'][] = array(
'key' => $podcast_sub_title_field_name,
'value' => $search_term,
'compare' => 'LIKE',
);
}
return $args;
}
So, this is my problem. I’ve tried sending a string type into my meta “observacao_intensidade_ataque” but it gives me this error:
{
"code": "rest_invalid_param",
"message": "Parâmetros inválidos: acf",
"data": {
"status": 400,
"params": {
"acf": "acf[observacao_intensidade_ataque] não é um de "
},
"details": {
"acf": {
"code": "rest_invalid_param",
"message": "acf[observacao_intensidade_ataque] não é um de ",
"data": {
"param": "acf[observacao_intensidade_ataque]",
"value": "testing"
}
}
}
}
}
If I send it as array it saves though:
"observacao_intensidade_ataque": {
"value": "1",
"label": "Teste"
},
Problem is, as an array, it does not work correctly although it get’s saved into my database.
I have other fields, all working as expected.
I’ve even checked here and it seems the select type field is supposed to support a “string” type – which obviously makes sense because that’s how it’s saved as a meta anyway.
I’ve tried to find people complaining about same problem but, strangely.
I’m using ACF Pro 6.2.9.
Hi, maybe someone can help me.
I have two post types: team and match.
In CPT “match” i have a post-object field which comes from CPT “team”.
Now i want to query all matches from a specific team, but i dont get the query to work.
Thank you!
Trying to return an array of posts with acf fields populated. My query gives me the desired data of posts although no population of acf Fields. Any help here is greatly appreciated
function my_events_current_func ( $request_data ) {
$date_now = date('Y-m-d');
$posts = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_query' => array (
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $date_now,
'type' => 'DATE'
)
),
'order' => 'ASC',
'orderby' => 'event_date',
'meta_key' => 'event_date',
'meta_type' => 'DATE',
));
return $posts->posts;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'thehub/v1', '/current/events', array(
'methods' => 'GET',
'callback' => 'my_events_current_func'
));
});
I have an ecoprovince field group with two fields. The one I want to target in my blade.php file is the Eco Province Locations. And in the Eco Province Locations specifically the field polygon_area_coordinates_for_ecozone. You Should be able to see them in my provided screenshots.The coordinates are dumped into a custom post type called ecoprovince.
I have the following blade php code
@php
// Set up the arguments for WP_Query
$args = [
'post_type' => 'ecoprovince', // Replace with your custom post type
'posts_per_page' => -1, // Fetch all posts
'fields' => 'ids', // Only get post IDs to improve performance
];
// Perform the query
$eco_zone_posts = new WP_Query($args);
// Initialize an array to store our eco zones data
$eco_zones_data = [];
// Loop through the posts
foreach ($eco_zone_posts->posts as $post_id) {
// Retrieve the entire group field 'ecoprovince_locations' first
$ecoprovince_locations = the_field('ecoprovince_locations', $post_id);
// Now you can access the subfield 'polygon_area_coordinates_for_ecozone'
// Ensure you access the subfield as a key of the group field array
$coordinates = get_sub_field('polygon_area_coordinates_for_ecozone') ?? '';
// Check if coordinates are not empty and add them to the array
if (!empty($coordinates)) {
$eco_zones_data[] = [
'coordinates' => $coordinates,
];
}
}
wp_reset_postdata(); // Important to reset post data after a custom query
@endphp
{{-- Debug output --}}
<div class="debug-output">
@dump($eco_zones_data)
@dump($eco_zone_posts)
</div>
Right now it outputs an empty array for the coordinates but there are coordinates in the post, there are two posts with coordinates published.
trying to figure out how to output the coordinates into an array after looping through them.
thanks ahead of time.
Hello,
I’ve used this function in the past to load the possible values of a field.
add_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
function load_combine_fields($field)
{
$productGroupID = $_GET['tag_ID'];
//get the field value of "filter" from the product group without loading the field
remove_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
$filters = get_field('filter', 'product_group_' . $productGroupID);
add_filter('acf/load_field/name=combine', 'load_combine_fields', 10, 3);
$field['choices'] = array();
if ($filters != null && is_array($filters)) {
foreach ($filters as $filter) {
$options = $filter['filter_options'];
foreach ($options as $option) {
$field['choices'][sanitize_title($option['value'])] = sanitize_title($option['value']) . ' (' . $filter['filter_title'] . ')';
}
}
}
error_log(print_r($field['choices'], true));
//$field['choices'] = array('1', '2', '3', '4');
return $field;
}
Nowadays it does not do anything. The log is beeing created so the function IS running, but the field options are just not beeing set.
Note: I think it has something to do with the “combine” field beeing a child of the repeater field “filter”. If I move the field outside the repeater, everything works.
Also: If i comment out everything but the hard coded choices at the end, the options are beeing set as 1,2,3,4.
Thanks!
hi
i am following this tutorial and the thing is that in the post and page editor, i can populate the select control with the meta fields, but in the site editor, when i want to use them in templates: it is populated only in archives templates, but no in the page template or the single post template.
i have this code:
const [acfMeta, setACFMeta] = useEntityProp('postType', postType, 'acf', postId);
as i said: in the archive templates acfMeta is populated so i can loop them and populate the select control with them. but not in the page template or the single post template, then it returns undefined.
any idea why and what can i do?
Hi, I have a ACF file field on a custom Post Type Resources, let’s call one of the posts, “PDF Post”. Whenever a user goes to the URL for “PDF Post”, I want them to be redirected straight to the File URL.
This will be applied throughout the Resources Post Type so that my users can use the Post URLs to go straight to the attached file.
I’m using this for the Redirect PHP.
<?php
header("Location: ".$newURL, true, 301);
exit();
?>
What’s the best way to return the insert the URL returned by the ACF File Field into the Redirect PHP?
Any help is appreciated. Thanks!
On this page in the documentation; https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
it is stated that the $args below will return all posts that have ‘location’ (array) equal to ‘Melbourne’. But I am finding, this will also return posts that have the ‘location’ equal to ‘Melbourne2’ or ‘Little Melbourne’
Is this correct? And if so, how would I get only those with ‘location’ equal to ‘Melbourne’?
At the moment I am having to test the results with in_array('location', array('Melbourne')
which seems a little clumsy.
<?php
// args
$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘event’,
‘meta_query’ => array(
array(
‘key’ => ‘location’,
‘value’ => ‘Melbourne’,
‘compare’ => ‘LIKE’
),
),
);
After changing to a different domain name ACF doesn’t recognise it. The message under ACF> Updates is:
Your site URL has changed since last activating your license, but we weren’t able to automatically reactivate it: You have reached the activation limit for the license.
I have the option to Deactivate License there, so is this what I do and then reactivate it for the new domain name?
I have a lifetime personal license.
Thanks