I think that ACF 4 is going to be discontinued and will no longer be getting any updates.
I would convert the current field to a dynamically populated select field.
A post object field stores:
If multiple selections are not allowed: A single post ID of the related posts
If multiple are allowed: an array of Post IDs
So your select field should have Post IDs as values and Post Titles as labels, this will mimic post object field, or you could set the label to something else.
The main difference with the two fields is that you will not have ACF to automatically populate an array of post objects and you’ll need to do this yourself. It is a simple process of doing a WP_Query using the returned value or array in the ‘post__in’ argument. If it’s a single ID then you should post__in should be an array with a single value.
If you convert the existing field(s) and you store the same values then all of your existing data should remain intact because the new field will have the same field key as the old field.
I found out the solution.
Please go to acf-qtranslate\src\acf_5\fields\wysiwyg.php line 32
Change add_action(‘acf/input/admin_footer’, array($this, ‘input_admin_footer’));
TO do_action(‘acf/input/admin_footer’, array($this, ‘input_admin_footer’));
I found out the solution.
Please go to acf-qtranslate\src\acf_5\fields\wysiwyg.php line 32
Change add_action(‘acf/input/admin_footer’, array($this, ‘input_admin_footer’));
TO do_action(‘acf/input/admin_footer’, array($this, ‘input_admin_footer’));
Ok, thank you.
I came up with a new solution just to count the number of values inside the two arrays:
add_action('acf/save_post', 'my_project_updated_send_email_custom', 10);
function my_project_updated_send_email_custom( $post_ID ) {
/* new and old field value */
$dokumenteOld = get_field('field_5ba11346c0289', $post->ID);
$dokumenteNew = '';
if (isset($_POST['acf']['field_5ba11346c0289'])) {
$dokumenteNew = $_POST['acf']['field_5ba11346c0289'];
}
/* get elements in array */
$countOld = count($dokumenteOld);
$countNew = count($dokumenteNew);
}
Now the problem is that both containt the same number of values when i a add a new line in the repeater field (the new count). I also can see the new value in both arrays.
Sorry, this is the last quesiton i ask i promise. Thank you so much for your help!
Checking a repeater field will be difficult. Not only to you need to contend with the fact that they are arrays of values, someone could also alter the order of the rows.
You may also be running into differences between inputted values and stored values that have nothing to do with something being changed. There can be instances where the values in $_POST[‘acf’] contain slashes \
While comparing arrays is possible, it would be a complicated process and I’m not sure that I can give you a reliable solution for, especially since the order of the rows can be changed. The best possible alternative is the serialize both values and compare that answer here https://stackoverflow.com/questions/7389176/compare-multidimensional-arrays-in-php
I had tried it with the get_field() option and queried if($field) as well and it still returns a value. So it sounds like I should change it to a repeater field then.
Hi,
sorry it’s my first topic 🙂
Maybe it will be clearer with proper code.
So, first, I have a CPT for courses.
In that CPT, I use ACF for the details of the courses.
One of the field is a repeater field : each course cans have multiple group (each group have a different start time and an URL to register).
On the courses page, I display the groups using the following code:
<?php if(have_rows('gestion_groupe')){ ?>
<div id="accordion">
<?php while (have_rows('gestion_groupe')): the_row(); ?>
<div>
<?php if (get_sub_field('fraisEQ') != NULL) { ?>
<div class="ligne"><span style="font-size:13px;"><strong>Groupe Emploi-Québec</strong> :
<?php echo get_sub_field('fraisEQ'); ?> $</span>
<button onclick="hiddenLinks('<?php the_sub_field('ns_lienMiaEQ'); ?>','<?php the_title(); ?>','<?php the_title(); ?>')" class="et_pb_button_mia">S'inscrire</button>
</div>
<?php
}
?>
</div>
<?php
endwhile;
?>
What I want here, is to display a button if there’s a group (get_sub_field…).
If the person click on the button, the popup will appears. I want to have the link in that pop-up. Each group have a different link…
My popup is an hidden div on the page :
<div id="overlay" onclick="off()">
<div id="overlayText">
[I have text...]
<a href="<?php echo the_sub_field('ns_lienMiaEQ'); ?>" class="et_pb_button_mia" target="_blank" id="miaLink">Button text</a>
And I’ve got a js function :
function hiddenLinks() {
document.getElementById("overlay").style.display = "block";
}
function off() {
document.getElementById("overlay").style.display = "none";
}
If it’s still unclear, let me know and thanks for the help.
No, not directly. The value stored in ‘place’ is the post ID. There is nothing stored for the ‘Homes’ post that has this information.
In order to do this you would need to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/
In this filter you would need to get the post title, or whatever it is from the other post that you really want to sort by and then save this value for the “Place” post in another meta value https://codex.wordpress.org/Function_Reference/add_post_meta
I cover this idea for repeater fields here https://acfextras.com/dont-query-repeaters/ but the principle would be the same for this, you’re just using different information.
My first suggestion would be to not do this the way you are planning. I would use (and I have used) Multilingual Press It basically uses WP multisite, it does not translate content for you it just keeps track of the how content is related from one site to the other and shows a widget for selecting the language and it keeps track of all the little details.
To do what you want to do using multiple fields would require using SESSION in PHP. Keeping track of what people have clicked and showing the correct content based on that. You might also want to consider automatically detecting the users language and showing the correct content.
Ratatat’s solution worked perfect for me. This is right out of my page template, the oembed is named “video”:
$video = get_field( 'video' );
if ( $video ) {
// Add autoplay functionality to the video code
if ( preg_match('/src="(.+?)"/', $video, $matches) ) {
// Video source URL
$src = $matches[1];
// Add option to hide controls, enable HD, and do autoplay -- depending on provider
$params = array(
'controls' => 0,
'hd' => 1,
'autoplay' => 1
);
$new_src = add_query_arg($params, $src);
$video = str_replace($src, $new_src, $video);
// add extra attributes to iframe html
$attributes = 'frameborder="0"';
$video = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $video);
}
echo '<div class="video-embed">', $video, '</div>';
}
I’m not sure what this means
that’s why the loop always calls the same slug because it finds it compiled even where it wasn’t.
If you share the code that’s giving you a problem it would be helpful to understand the issue.
Have you looked at the multiple markers example part of this page? https://www.advancedcustomfields.com/resources/google-map/
Another helpful resource here https://ashley-cameron.com/blog/google-maps-with-multiple-unique-markers-using-acf/
I’m sorry for the confusion John. Okay, so I have 800 or so custom_post_types (records) which each have a letter they are being sorted by (either the first name of the musical artist or the band name). These values are chosen inside the custom_post_type via an ACF. WordPress then uses the standard while loop to list out all of the records (which are already in the correct order).
So what I am looking to do is have the code determine where the first custom_post_type with an ACF ($sort) value of “A” is being looped in, and inject a custom div with the text “A” before that. Then before first custom_post_type ACF value or “B” begins, inject a custom div with “B” in… and so on and so fourth all the way until “Z”.
So I am not sure if the best methodology would be to do a php count of all the custom_post_types with the ACF ($sort) value of “A”, “B”, “C”, etc before the while loop and then just have some custom php conditional statement tied into the while loop so that the code knows that after 200 or so entries it needs to insert some html code identifying that the user is now viewing “B” custom_post_types so, then at 340 “C”, etc.
The end code I am hoping the html spits out is…
<div id="ajax" class="records row">
<div id="artist-a">A</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A01</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A02</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A03</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">A04</div>
<div id="artist-b">B</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B01</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B02</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">B03</div>
<div id="artist-c">C</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C01</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C02</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C03</div>
<div class="record col-xs-6 col-sm-4 col-md-3 col-lg-2 col-xl-2">C04</div>
Of course these numbers are dynamic and dependent on however many entries (custom_post_types) exist in the back-end of the system.
If there is a specific “company” that exactly matches the entered values, then ACF could work. To us only ACF this would pretty much require that you enter every zip code that each company covers so that there is a 1 to 1 lookup.
If you are looking for a “radius” type of search, looking for any company that is close to the zip code entered so that you don’t need to enter every zip code, then ACF is probably not the correct choice. There is no functionality in ACF to do this and you’d need to build this yourself. For something like this I would go with the pro or gold addition of WP Google Maps https://www.wpgmaps.com/ or get everything with the developer bundle.
First question, does your post object field allow multiple of single values. If it contains multiple then you query is close, it should be
array(
'key' => 'place',
'value' => '"'.$post_id.'"',
'compare' => 'LIKE'
);
If it only contains 1 then it should be
array(
'key' => 'place',
'value' => $post_id
'compare' => '='
);
The next problem is with what your returning for args
function related_homes( $args, $field, $post_id ) {
// since $meta_query array does not exist yet you shouldn't use
// $meta_query[] =
$meta_query = array(
array(
'key' => 'place',
'value' => $post_id,
'compare' => 'LIKE'
)
);
// the correct argument key is 'meta_query'
$args['meta_query'] = $meta_query;
// return
return $args;
}
In order to use this other plugin you need to understand how all of the various fields in ACF are stored. Updating a field in ACF requires 2 entries in the database. One for the meta_key, which is the same as the field name and the second for the ACF field key reference.
Example
meta key = $field_name = the value of your field
acf field key reference = "_{$field_name}" = the acf field key
Updating a value without the field key reference will work for basic fields that only store basic text values. This includes Text, Text Area, Number, Email, URL, Password, WISIWYG
All other fields will not work correctly if the field key reference is not in the database.
Repeater fields are a special case. A repeater field stores many values.
meta_key | value
"{$repeater_field_name}" | number of rows in repeater
"{$repeater_field_name}_{$index}_{$sub_field_name}" | value of one sub field
And each has an ACF reference field
meta_key | value
"_{$repeater_field_name}" | field key of repeater
"_{$repeater_field_name}_{$index}_{$sub_field_name}" | field key of sub field
On top of this, depending on the type of sub field, if it is not a basic text field type then your values will also need to conform to how ACF stores the values for each of these fields.
the problem is that you are looking at the actual term currently set for the post that is stored by WP.
$main_post_cat = noir_get_team_term($options['post_id'], "team_category", 'slug');
You need to look at this, but you also need to check to see if ACF has included the currently selected therm in the $options
that it is passing to the filter. This is actually more important then testing the posts current terms, but you need to do both, first checking the $options
and if it is not set or it is empty then checking against the post’s current terms.
If nothing has changed since the last time I created a custom location rule then the terms selected will be in $options['taxonomy']
One of my old examples shows this https://github.com/Hube2/acf-filters-and-functions/blob/master/acf-post-category-ancestor-location-rule.php
It is not 100% clear by your question what type of field you’re using. If you are working with a user field, a user field stores only the User ID values in and array. The same is true of a relationship field if that is what you’re using. When you use update_field()
you need to supply ACF with the value as it needs to be stored, in this case an array of ID values.
You can get the current value unformatted by using the 3rd parameter.
$current_mentees = get_field('current_mentees', $mentor_post_id, false);
then you can add a new ID to the array
$current_mentees[] = 125; // or whatever code your using to get the ID to add
then you update the field
update_field('current_mentees' , $current_mentees , $mentor_post_id);
Sorry, it is not 100% clear what you need help with.
You already have all the posts sorted by this “sort” field when you do the query that’s not shown?
You want to “group” the posts in some way by the value of the custom field?
If this is the case then the basic idea would be something like this
<?php
// your query here
if (have_post()) {
$last_sort = '';
while (have_posts()) {
the_post();
$sort = get_field('sort'); // Gives The Sort Letter
if ($sort != $last_sort) {
// the sort leter has changed
?>
<div id="sort-<?php echo $sort; ?>"><?php echo $sort; ?></div>
<?php
// set $last_sort to new $sort
$last_sort = $sort;
} // end if short changed
} // end while have posts
} // end if have posts
?>
Ah, I’m glad it’s working now—apparently this functionality (or this filter?) is limited to Pro.
I would start a new topic for your other request… I don’t know anything about Buddypress, but the user dropdown wouldn’t search that data unless it saved them as actual WordPress users. Best of luck! 🙂
Oh, I have found solution faster than I thought.
I must use acf/save_post
but with 20 priority which runs after saving $_POST data.
I’m taking subcategory value from post, checking if that term exist and add it to post using wp_set_post_terms
.
Code:
function my_acf_save_post_after($post_id) {
require_once('wp-load.php' );
require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
// bail early if no ACF data
if (empty($_POST['acf'])) {
return;
}
//get post value
$parent_cat2 = get_field('curr_categories', $post_id);
$test_cat2 = get_field('cat_test', $post_id);
$term_id = term_exists( $test_cat, 'category', $parent_cat2 );
wp_set_post_terms( $post_id, $term_id, 'category', true );
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
I already wrote earlier. I put a clean version of WordPress on a test site. I installed the Storefront theme. Installed plugins – Woocommerce, ACF and ACF for WooCommerce. Created custom fields and placed them in the my-account of the user WooCommerce.
I do not have third-party plugins on the test server, which do not work well.
The only question is the plugin “ACF for WooCommerce”, which saves to the database “field_5ba168bfdcb58”. Why can not this plugin save “user_phone”?
I had the same problem, but re-installed WordPress using the button on the updates page that says
If you need to re-install version 4.9.8, you can do so here:
and then I ran the plugin update and it worked.
Someone of the ACF team? This is quite a big bug for me. I can not use the newest version of the plugin in combination with the post object field because of this.
I think I found a simpler way to do this –
// Get the page title
echo '<h1 class="template-title">';
$title = the_title();
echo '</h1>';
Then add css to put it over the hero image:
/* Custom Template Pages
---------------------------------------------------------*/
.template-title {
position: relative;
top: 70%;
z-index: 100;
color: white;
text-align: center;
font-size: 50px;
font-size: 5rem;
}
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.