Hey @hube2 Thanks a lot!! đŸ™‚
It’s funny because I just found the same solution :-))
Here is what I got:
(function($) {
jQuery( document ).ready( function( $ ) {
if ( typeof acf !== 'undefined' ) {
acf.addAction('load_field', function( field ) {
if ( field.data.name === 'locations') {
const locationsField = field.$el[0];
const acfTable = locationsField.querySelector('.acf-table');
const acfTableRows = acfTable.querySelectorAll('.acf-table .acf-row');
acfTableRows.forEach((row, index) => {
const handle = row.querySelector('.acf-row-handle');
handle.classList.remove('order');
});
}
});
}
});
})(jQuery);
I will have a look at what you did as well…
Thanks @hube2 Yes, I have seen that post and have also added my own comment a few days ago. I did not find anything there that works.
Could someone help me explain the Javascript API?
I’ve tried this, but am looking for an action that runs after Sortable is set. “ready_field” runs before.
acf.addAction('ready_field', function( field ){
field.$el.addClass('new-way');
});
Is there more documentation on Field Actions?
Hi. Did anybody find a way to do this with the new JavaScript API? For some reason I cannot find the element that is sortable. I tried all of the below methods. I tried other things too, but can’t get working
jQuery( document ).ready( function( $ ) {
if ( typeof acf !== 'undefined' ) {
const field = acf.getField('field_62fb6d4aa3dce');
// field.sortable('disable');
// field.$el.sortable('disable');
// field.$el[0].sortable('disable');
}
});
Any ideas? đŸ™‚
Hi John. I don’t believe there are. The Post Object does not allow for this kind of UI.
Alright John no problem, maybe I am not quite understanding it, because it is obviously possible to do so. But if ACF does not work that way then that is fine. It was only a suggestion. Now I know. đŸ˜‰
Okay, but it’s possible to do with the show_user_profile
or the edit_user_profile
and user_contactmethods
hook. This is just a feature request. I thought maybe this would be a nice little enhancement to ACF đŸ˜‰
Alright sure. For instance, I have this function I usually use on my sites:
add_filter( 'user_contactmethods', function( $contactmethods ) {
$contactmethods['company_name'] = __( 'Company' );
$contactmethods['address'] = __( 'Address' );
$contactmethods['zip'] = __( 'Postal code' );
$contactmethods['city'] = __( 'City' );
$contactmethods['phone'] = __( 'Phone' );
return $contactmethods;
}, 10, 1 );
However, there was a website where I need a calendar for the birthday field. So I added such a field to the user edit page in the controlpanel with ACF. However, the birthday field was situated far down the page, all by itself. It would have been so much more user-friendly, if it was up the page, together with the other contact fields. Does that make sense? đŸ™‚
Please let me know if I should elaborate further đŸ˜‰
Regards Vayu
Thanks Jarvis.
I see that to do this, one would have to filter the search query and it becomes quite harry. https://wordpress.stackexchange.com/questions/11822/how-to-limit-search-to-post-titles
I have the same issue. I don’t know if it also searches the post content maybe?
It looks like it has something to with the acf_register_block_type function and therender_template that is used. I have an <header> HTML tag in the template file, that it doesn’t seem to like. When I change it to a <div> tag, then no error.
Okay, so the $testimonials variable has found x number posts?
Are you using the correct post ID inside the_field() and get_field()?
Which part is not working? Can you be more specific?
can you print out to the screen how many testimonials this var contains: var_dump($testimonials)
Grid block?
Have you followed this setup guide?
https://www.advancedcustomfields.com/resources/blocks/
$testimonial_include_image = get_field(‘testimonial_include_image’);
$testimonial_how_many = get_field(‘testimonial_how_many’);
$testimonial_cols = get_field(‘testimonial_cols’);
$testimonial_author = get_field(‘testimonial_author’);
$testimonial_content = get_field(‘testimonial_content’);
$testimonial_image = get_field(‘testimonial_image’);
The above code is outside the loop. the_field and get_field functions should have a post ID if not such ID is given.
https://www.advancedcustomfields.com/resources/get_field/
Also this line should end with a p tag:
<p class="swd_testimonial_content"><?php the_field('testimonial_content'); ?>
Could it be that there is white space in this line, between “$testimonials-> have_posts()”?
while($testimonials-> have_posts()):
This would require some programming. You would want to use some WooCommerce hooks. Probably this hook “woocommerce_product_thumbnails”. But it might require others too.
https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/
https://docs.woocommerce.com/document/introduction-to-hooks-actions-and-filters/
Thank you so much @hube2! đŸ™‚ I really appreciate your feedback and for sharing your code. Here is what I ended up using. I kept your naming convention for convenience.
class MY_PROJECT_NAME_acf_filters {
// variable for row index
private $my_field_name_index = 0;
public function __construct() {
// add a filter when preparing repeater
add_filter( 'acf/prepare_field/key=field_601cf9424f9da', array( $this, 'init_my_field_name_index' ), 10, 1 );
add_filter( 'acf/prepare_field/key=field_6023ad409d89d', array( $this, 'filter_my_sub_field_name' ), 10, 1 );
// add filter for ths sub field that you want to filter
add_filter( 'acf/prepare_field/key=field_602e8a8821e89', array( $this, 'filter_my_sub_sub_field_name' ), 10, 1 );
}
public function init_my_field_name_index( $field ) {
$this->my_field_name_index = 0;
return $field;
}
public function filter_my_sub_field_name( $field ) {
// after filtering increment the field index
$this->my_field_name_index++;
// return the field;
return $field;
}
public function filter_my_sub_sub_field_name( $field ) {
$field['choices'] = [];
$row_index = $this->my_field_name_index - 2;
$product_id = (int) get_user_meta( 2, 'add_products_' . $row_index . '_produkt', true );
if ( ! empty( $product_id ) ) {
$pewc_group = new WP_Query( [
'posts_per_page => ' -1,
'post_type' => 'pewc_group',
'post_parent' => $product_id,
'post_status' => 'publish'
] );
if ( $pewc_group->have_posts() ) {
while( $pewc_group->have_posts() ) { $pewc_group->the_post();
$field['choices'] = [];
$group_title = get_the_title();
$group_id = get_the_ID();
$pewc_field = new WP_Query( [
'posts_per_page => ' -1,
'post_type' => 'pewc_field',
'post_parent' => get_the_ID(),
'post_status' => 'publish',
'order' => 'ASC'
] );
if ( $pewc_field->have_posts() ) {
while( $pewc_field->have_posts() ) { $pewc_field->the_post();
$field_label = get_post_meta( get_the_ID(), 'field_label', true );
if ( ! empty( $field_label ) ) {
$field['choices'][get_the_ID()] = $field_label . ' (' . get_the_ID() . ')';
}
}
wp_reset_postdata();
}
}
wp_reset_postdata();
}
}
// return the field;
return $field;
}
}
new MY_PROJECT_NAME_acf_filters();
Thanks again John! So with your help I put this together and now it works like I want.
add_filter( 'acf/pre_save_post' , function( $post_id ) {
// check if this is to be a new post
if ( $post_id != 'new' ) {
return $post_id;
}
if ( isset( $_POST['add-to-cart'] ) && isset( $_POST['product_id'] ) ) {
unset( $_POST );
}
// return the new ID
return $post_id;
}, 10, 1 );
Unfortunately, this did not work. The acf_form() still saves the data to the product it is embeded on.
How can I remove the “Solved” tag?
Thanks John!
Hi again John.
Could not get your code to work, the code you so kindly share here: https://acfextras.com/dont-query-repeaters/
So I modified it and had to use the field keys like so:
add_action('acf/save_post', function( $post_id ) {
$meta_key = '_book_authors';
$saved_values = array();
$authors = $_POST['acf'];
if( $authors ) {
foreach( $authors['field_55bf6c9024b5f'] as $key => $author ) { // field_55bf6c9024b5f: ACF field key for "book_authors" meta field
$author_id = $author['field_55dafbfa91614']; // field_55bf6c9024b5f: ACF field key for "book_authors" meta field
add_post_meta( $post_id, $meta_key, $author_id, false );
}
}
}, 20, 1 );
Thank so much John, that’s a great answer! đŸ™‚
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.