I’d correct some mistake.
Here is the new code :
function my_posts_where( $pagepdf ) {
$pagepdf = str_replace("meta_key = 'pagesdupdf_$", "meta_key LIKE 'pagesdupdf_%", $pagepdf);
return $pagepdf;
}
add_filter('posts_where', 'my_posts_where');
// args
$args = array(
'numberposts' => -1,
'category' => 2,
'post_type' => 'post',
// 'meta_query' => array(
// 'key' => 'pagesdupdf_$_contenu_de_la_page',
//'value' => '"' . get_search_query() . '"',
// 'compare' =>'EXISTS')
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
if( have_rows('pagesdupdf') ): ?>
<ul>
<?php while( have_rows('pagesdupdf') ): the_row();
$motcherche = get_search_query();
$motsdepage = get_sub_field('contenu_de_la_page');
foreach( $motdepage as $mot ):
if ( $motcherche == $mot) :
// vars
$image = get_sub_field('image_de_la_page');
$content = get_sub_field('contenu_de_la_page');
$link = get_sub_field('url_de_la_page');
?>
<li>
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php if( $link ): ?>
</a>
<?php endif; ?>
<?php echo $content; ?>
</li>
<?php endif; endforeach; endwhile; ?>
</ul>
<?php endif;?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post().?>
This would require creating a filter for CF7, but I don’t know if that is possible. In any case this is a modification you’d need to make to CF7 and not something that can be done by adjusting ACF. I have been unable to find any information on doing this. If you can figure out how to dynamically populate a CF7 checkbox field then someone here can probably help you get the values from ACF.
Hello,
Cheers!
Whether you add all of the rows using update_field(), or you add each row, the problem is the same.
ACF uses the built in WP function update_post_meta() or one of the variant functions that does the same thing. This function can only update a single custom field and it causes from 2 or 3 queries to be run each time it is called. First it sees if the meta_key/meta_value exists and then it inserts or updates depending on that. To be honest, I’m not sure what triggers the 3rd query and it does not always happen. In addition to this ACF adds a field key reference meta_key and this update causes another 2 or 3 queries to be run. So you have a total of 4 to 6 queries for every field updated.
This is a limitation in ACF, but the root cause is a limitation in WP due to the way it handles custom fields/meta values.
Unfortunately, there isn’t workable solution. SQL does allow inserting multiple rows to a table in a single query, but doing so causes other issues, like the meta cache not being updated correctly. The only real solution would be to construct custom queries for inserting the values with all the correct meta_key/meta_value pairs and then directly insert the values to the DB using SQL rather than allowing WP to handle the work.
I don’t see anything wrong with that query and it should be working. Is the date field in a repeater, of somehow nested in another field that allows nesting?
Thanks John, only 1 person for the forums is quite some challenge I guess.
Opened a ticket. If we find a solution, I will add it here, so other people know about this issue and possible fix.
This is not really a support forum. The only people answering questions here are other users.
My suggestion is to deactivate all other plugins and switch to one of the 20XX themes. If you are still seeing the issue then open a bug report here https://www.advancedcustomfields.com/contact/
If you are not seeing an issue then come back with what other plugin or theme is causing the problem and someone may be able to help you out.
If it’s an ACF field it does not store JSON. ACF fields that contain arrays store serialized values.
There isn’t WP_Query() on fields like these and the best option is what you suggest, store the value you want to search and filter on into it’s own meta_key.
Here is the action and filter I’m using to show on product page and the cart:
function save_my_custom_product_field( $cart_item_data, $product_id ) {
$custom_field_value = get_field( 'install_fee', $product_id, true );
if( !empty( $custom_field_value ) )
{
$cart_item_data['install_fee'] = $custom_field_value;
// below statement make sure every add to cart action as unique line item
$cart_item_data['unique_key'] = md5( microtime().rand() );
}
return $cart_item_data;
}
add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart', 10, 2 );
function render_meta_on_cart( $cart_data, $cart_item ) {
$custom_items = array();
// Woo 2.4.2 updates
if( !empty( $cart_data ) ) {
$custom_items = $cart_data;
}
if( isset( $cart_item['install_fee'] ) ) {
$custom_items[] = array( "name" => "Install Fee $", "value" => $cart_item['install_fee'] );
}
return $custom_items;
}
Hi @howdy_mcgee
Thanks for the bug report,
Elliot here – ACF devβββ.
Sorry about this issue, it is easily solved.
Can you please edit the ‘api-terms.php’ file in question and change the acf_get_taxonomy_labels() function to:
function acf_get_taxonomy_labels( $taxonomies = array() ) {
// default
if( empty($taxonomies) ) {
$taxonomies = acf_get_taxonomies();
}
// vars
$ref = array();
$data = array();
// loop
foreach( $taxonomies as $taxonomy ) {
// vars
$object = get_taxonomy( $taxonomy );
$label = $object->labels->singular_name;
// append
$data[ $taxonomy ] = $label;
// increase counter
if( !isset($ref[ $label ]) ) {
$ref[ $label ] = 0;
}
$ref[ $label ]++;
}
// show taxonomy name next to label for shared labels
foreach( $data as $taxonomy => $label ) {
if( $ref[$label] > 1 ) {
$data[ $taxonomy ] .= ' (' . $taxonomy . ')';
}
}
// return
return $data;
}
Just updated to newest version, then tried re-updating after reading this post. I’m still getting errors when try to use Page Link fields on the backend.
acf-input.min.js?ver=5.7.2:formatted:4826 Uncaught TypeError: Cannot read property 'id' of undefined
at HTMLInputElement.<anonymous> (acf-input.min.js?ver=5.7.2:formatted:4826)
at HTMLInputElement.dispatch (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:3)
at HTMLInputElement.r.handle (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:3)
at Object.trigger (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:3)
at Object.a.event.trigger (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:9)
at HTMLInputElement.<anonymous> (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:3)
at Function.each (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:2)
at a.fn.init.each (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:2)
at a.fn.init.trigger (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,jquery-ui-resizable&ver=4.9.8:3)
at d.triggerSelect (select2.min.js?ver=3.4.1:21)
Hi guys
Thanks for the email,
Elliot here – ACF dev.
Thanks for the bug report and sorry for the JS errors.
We have quickly fixed the issue and re-uploaded the plugin files online.
Can you please re-download the ACF PRO plugin files from your account, this should solve the problem.
https://www.advancedcustomfields.com/my-account
Tip: You can also trick ACF into re-updating itself by editing the main “acf.php” plugin file and changing the two references of “5.7.2” to “5.7.1”. This will allow WP to check for plugin updates and you can then re-update the plugin π
I think you have a display format or output format when you create the acf date field.
If not you can use.
$newDateFormat = date("F j, Y",strtotime($oldDateFormat));
This should work and do what I want, but it does not work. Someone to help ?? I do not know where I’m going wrong.
$args = array(
'taxonomy' => 'custom_taxonomy',
'orderby' => 'name',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'my_custom_field', // name of custom field
'value' => "{$post_id}", // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
);
$atv = get_terms($args);
var_dump($atv)
Try this:
$fieldname = get_sub_field_object('col_left');
$value = $fieldname['_name']; ?>
<div class="<?php echo $value; ?>">Blablabla</div>
This should give you
<div class="col_left">Blablabla</div>
How to get Image Url
In setting i check image url and name of field is ‘image’
in editor i write this
the_field('image', "user_27" );
but it returns me image id not url
how can i fix this???
Yes. In my example it is a flexible content field .
Thanks for your answer. I’m searching for something like this:
$fieldname = field name of the marked the_sub_field('col_left');
<div class="<?php echo $fieldname; ?>">Blablabla</div>
Gonna need more information here I think.
But it looks like it’s a repeater field (or a flex field/ group field) they are all repeaters and you already have the field name
if (get_sub_field('col_left')) {
?><div class="col_left"><?php the_sub_field('col_left'); ?></div><?php
}
I’m not sure how far you’ve got with this but this works for me.
acf.add_action('google_map_init', function( map, marker, $field ){
// map (object) google map object returned by the google.maps.Map() function
// marker (object) marker object returned by the google.maps.Marker() function
// $field (jQuery) field element
var autocomplete = new google.maps.places.Autocomplete( $field.find('.search')[0] );
autocomplete.addListener('place_changed', function(e) {
var place = autocomplete.getPlace();
// your code here...
});
});
I was able to upgrade the logic of my loop to be manipulated by ACF fields (yeaahh!!!), for example, I can filter the get_post loop by my meta_query of ACF data as shown below…
//BUILD THE LOOP AND LOAD THE POSTS
function ithub_exec_summary_landing_loop() {
//DEFINE OUTPUT VAR
$out = '';
//LOOP - GET AL EXECUTIVE SUMMARIES VIA GET_POSTS()
$args = array(
'numberposts' => -1,
'orderby' => 'modified',
'order' => 'ASC',
'category_name' => 'executive-summary',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'product_owner',
'value' => 'larry',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'sally',
'compare' => 'LIKE'
),
array(
'key' => 'product_owner',
'value' => 'bob',
'compare' => 'LIKE'
)
)
);
$mExecSumPosts = get_posts($args);
//REFERENCE LOOP FOR PREVIEWING REVISIONS
if ($mExecSumPosts) {
foreach ($mExecSumPosts as $post):
setup_postdata($post);
//DEFINE LOOP VARS
$mtitle = $post->post_title;
$mpublisheddate = get_the_time('Y-m-d', $post->ID);
$mformateddate = date("l F jS, Y", strtotime($mpublisheddate));
//OUTPUT DATA
$out.= "<div class='row'>";
$out.= "<div class='col'>";
$out.= "<h3><a href='{$post->post_name}'>{$mtitle}</a> <span class='h5 text-secondary'>: Status Date of {$mpublisheddate} | </span></h3>";
$out.= "</div>";
$out.= "</div>";
endforeach;
}
return $out;
}
wp_reset_postdata();
}
…But! How can I output the product owner name (larry, sally, or bob) in this get_posts loop, for each post that is loaded? I have a feeling I may need to create a second get_posts() loop, but don’t know what that looks like from this point forward. Any help would be awesome!
I have multi users with same role
i want to get all acf data where role is equal to educator
is there any functionality which provide me my requisite data ??
For anyone who may find this in the future, I was able to achieve this by use the ACF Post-2-Post plugin, as well as the acf/fields/relationship/query
filter.
Inside the filter, I only populate the results with ‘Lessons’ that have either no value (”) or have had a value set, but no longer do (‘a:0:{}’). (That’s ACF’s markup.)
$args['meta_query'] = array (
'relation' => 'OR',
array (
'key' => 'lessons',
'value' => '',
'compare' => '=',
),
array (
'key' => 'lessons',
'value' => 'a:0:{}',
),
);
Value in meta query should contain only variable, like this
'meta_query' => array(
array(
'key' => 'shift_volunteers',
'value' => $current_user_id,
'compare' => 'LIKE'
),
)
Tested – work like a charm π
I have found a solution:
We can use update_field to add new rows to a repeater inside a group.
1. Get all values of the fields inside that group
2. Manipulate the resulting array adding new values in the repeater’s array
3. Update the group field.
It works even if the repeater never had any rows.
$pachet_8 = get_field("pachet_8", $post_id);
$pachet_8['rata_3']['plati'][] = array(
"suma" => 1001,
"data_platii" => "10.10.2018"
);
update_field("pachet_8", $pachet_8, $post_id);
I have the same problem. I have a repeater inside a group. I can’t add new rows to the repeater, programatically. I have tried using add_row with field names or keys. add_row returns integers but in the backend I can’t see any values.
I have tested also with a repeater outside the group. On that it works using add_row.
Thanks for any help!
add_row(
"field_5b606d31f4bb9",
array(
"field_5b607763dc795" => 100,
"field_5b606d3bf4bba" => "10.10.2018"
),
$post->ID
);
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.