Thank you mate. It works. If somebody has “Fatal error: [] operator not supported for strings” just add $field[‘taxonomy’] = []; in top of the function like this;
add_filter('acf/load_field/key=field_60c224887921d', 'load_just_categories_filter', 12, 1);
function load_just_categories_filter( $field ) {
$field['taxonomy'] = [];
$terms = get_terms( array(
'taxonomy' => 'category',
'hide_empty' => false,
//'hierarchical' => 1,
'parent' => 0
) );
if ( !empty($terms) ) {
foreach( $terms as $term ) {
$field['taxonomy'][] = 'category:'.$term->slug;
}
}
return $field;
}
Hi, is there any update about this problem ?
Hi @onoweb , can you look my code or do you have any suggestion about that ? Thanks in advance.
Hi, is there any update or news about repeater field ?
i was able to save normal fields to product variation but when i create repeater field it doesnt save the value, here is my code;
add_filter('acf/location/rule_values/post_type', 'acf_location_rule_values_Post');
function acf_location_rule_values_Post( $choices ) {
$choices['product_variation'] = 'Product Variation';
return $choices;
}
add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
global $abcdefgh_i;
$abcdefgh_i = $loop;
add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
$acf_field_groups = acf_get_field_groups();
foreach( $acf_field_groups as $acf_field_group ) {
foreach( $acf_field_group['location'] as $group_locations ) {
foreach( $group_locations as $rule ) {
if( $rule['param'] == 'post_type' && $rule['operator'] == '==' && $rule['value'] == 'product_variation' ) {
acf_render_fields( $variation->ID, acf_get_fields( $acf_field_group ) );
break 2;
}
}
}
}
remove_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
}, 10, 3 );
function acf_prepare_field_update_field_name( $field ) {
global $abcdefgh_i;
$field['name'] = preg_replace( '/^acf\[/', "acf[$abcdefgh_i][", $field['name'] );
return $field;
}
add_action( 'woocommerce_save_product_variation', function( $variation_id, $i = -1 ) {
if ( ! empty( $_POST['acf'] ) && is_array( $_POST['acf'] ) && array_key_exists( $i, $_POST['acf'] ) && is_array( ( $fields = $_POST['acf'][ $i ] ) ) ) {
foreach ( $fields as $key => $val ) {
update_field( $key, $val, $variation_id );
}
}
}, 10, 2 );
function xxx_admin_head_post() {
global $post_type;
if ($post_type === 'product') {
wp_register_script( 'xxx-acf-variation', get_template_directory_uri() . '/inc/ss.js', array(
'jquery-core',
'jquery-ui-core'
), '1.1.0',
true ); // Custom scripts
wp_enqueue_script( 'xxx-acf-variation' ); // Enqueue it!
}
}
/* actions fired when adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'xxx_admin_head_post' );
add_action( 'admin_head-post-new.php', 'xxx_admin_head_post' );
https://wordpress.org/plugins/options-importer/ plug-in solve my problem.
First i export all options to json, and then delete unnecessary lines, and then import new site. It’s ok now !
Thanks in advance.
Hi, i have created theme options area with acf. So i want to export demo theme fields values to xml, which users can be make settings as same as demo site.
Is solution works for you Gitaadi ?
Hi again, thanks for your reply but i think there is a misunderstanding.
I want to show last row as a post.
But my code show first row.
Its my problem
Any news about that ?
So i cannot loop posts with same taxonomy ha ???
i have a custom post type which “film” and they have custom taxonomies like genres “scary” “history” “drama” . When you enter a single-film.php i want in bottom some of 5 post which they also same taxonomies like “scary” or “history”
I know we can make it in wordpress panel but i dont want to do it manually. I want automatic loop for that.
Hi jamesstaub, can you share us this script ?
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.