Found a solution:
JS
acf.add_filter('select2_ajax_data', function(data, args, $input, field){
const post_type_field = acf.findFields({
name: 'post_type',
sibling: field,
limit: 1,
});
const post_type_value = post_type_field.find($('select')).val();
if (post_type_value) {
data.post_type = post_type_value;
}
return data;
});
PHP
add_filter('acf/fields/post_object/query/name=featured_posts', function($args){
if (!empty($_POST['post_type'])) {
$args['post_type'] = esc_attr($_POST['post_type']);
}
return $args;
});
@christian-denatorange-fr Your code should work when the repeater field is used as a flexible content?
In my case, I have a layout with a selector and a repeater:
acf.addAction('new_field/name=preset', foo);
function foo(field) {
field.on('change', function() {
const repeater = acf.getField('field_page-builder_sections_row-module_row_columns');
let $row = '';
$row = repeater.add();
});
}
But nothing happens.
When you have a flexible content area and layouts withs tabs:
acf.add_filter('validation_complete', function(json, $form){
if(json.errors) {
$.each(json.errors, function(key) {
const field = $('[name="' + json.errors[key].input + '"]', $form).parents('.acf-field');
const parent_field = field[field.length - 2];
const tab = $(parent_field, $form).prev('.acf-field-tab').attr('data-key');
$('.acf-tab-wrap a[data-key=' + tab + ']', $form).click();
});
}
return json;
});
Found the solution here: https://support.advancedcustomfields.com/forums/topic/sending-user-to-tab-on-validation-errors/
Thanks for the help John!
As I’m working with flexible content, I had to get the index:
$index = preg_replace('/\D/', '', $field['id']);
$post_type = get_field('content_'.$index.'_select_post_type');
Thanks for the reply @hube2. Just a question: how can I get the selected value of the other field inside prepare_field
filter? How can I get the selected post type to return the related taxonomies?
Hey @elliot. Here what I’m using:
– ACF PRO: 5.8.0-beta1 (also tested in ACF 5.7.7)
– Gutenberg: in this WP version, the plugin was merged to the core
– WordPress: 5.0-beta1-43823
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.