I found a solution after reading this post: http://support.advancedcustomfields.com/forums/topic/when-using-save_post-action-how-do-you-identify-which-options-page/
While using WP get_current_screen()-function you can check if the ID in the output-array contains the slug of your specific option page.
http://codex.wordpress.org/Function_Reference/get_current_screen
For example you have an options page called “adverts” and want run the function mentioned above when you save this specific option page:
function clear_advert_main_transient() {
$screen = get_current_screen();
if (strpos($screen->id, "acf-options-adverts") == true) {
delete_transient('advert_main_transient1');
delete_transient('advert_main_transient2');
delete_transient('advert_main_transient3');
}
}
add_action('acf/save_post', 'clear_advert_main_transient', 20);
Now WP Transients make even more fun and will save you tons of queries if you have complex acf-fields and loops! 🙂
Just to supply more information on this,
I’m receiving the following before the first field in the field group is displayed.
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/acf.php on line 532 Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/acf.php on line 532
I’m receiving the following errors on the following lines. I can see fully the first field that renders completely fine and the the 2nd doesn’t. Theres a total of 6 fields in the field group.
The 2nd field should be a repeater which includes a wysiwyg and 2 text fields.
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 98
field-
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 98
" data-type="
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 98
" data-id="
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 98
">
<div class="field_meta">
<table class="acf widefat">
<tr>
<td class="field_order"><span class="circle">
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 102
1</span></td>
<td class="field_label">
<strong>
<a class="acf_edit_field row-title" title="Edit this Field" href="javascript:;">
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 105
</a>
</strong>
<div class="row_options">
<span><a class="acf_edit_field" title="Edit this Field" href="javascript:;">Edit</a> | </span>
<span><a title="Read documentation for this field" href="http://www.advancedcustomfields.com/docs/field-types/" target="_blank">Docs</a> | </span>
<span><a class="acf_duplicate_field" title="Duplicate this Field" href="javascript:;">Duplicate</a> | </span>
<span><a class="acf_delete_field" title="Delete this Field" href="javascript:;">Delete</a></span>
</div>
</td>
<td class="field_name">
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 114
</td>
<td class="field_type">
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 115
Notice: Undefined index: in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 115
</td>
<td class="field_key">
Notice: Uninitialized string offset: 0 in /wp-content/plugins/advanced-custom-fields/core/views/meta_box_fields.php on line 116
Any advice greatly appreciated.
Sorry avs4toin, my question is about a functionality of ACF! What DocuSign is and what about connection with ACF?
Quick Solutions:
Hi Etienne,
I have the same requirement as you…kind of. And I am stumped. I was going though the code that worked for you, and I have a question. At the cost of appearing a dud…here goes the question 🙂
In the query here, is “rule” the name of your field group?
Many Thanks,
Sarah
Try
<?php $clients = new WP_Query(array(
'post_type' => 'clients',
'posts_per_page' => -1,
));?>
I did not found this before
http://www.advancedcustomfields.com/faq/field-value-wont-save/
I just made the name of the slugs smaller and now is working just fine!
In case someone is having this issue and wants to fix this, you need to load the form through ajax once you open your modal, as otherwise the script wont generate the fields required for some of the functionality to work.
You can refer to this here:
http://www.advancedcustomfields.com/resources/acf_form/
Thanks to James Stout from the Advanced Custom Fields support, this is a quality product.
I decided to give this a shot and also decided it would be best to allow for configuring the Featured post from within the post itself or from my site’s home page (i.e., front page). I also wanted to ensure this would work for scheduled posts. I’d love feedback on more effective methods or if any of this code can be tightened up at all.
My custom post type is article
and I setup two fields: a checkbox within each article
and a Post Object field on the home page, both fields called featured_article
. Here’s how I did it:
function allow_only_one_featured_article($post_id, $post) {
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
$homepage = get_option('page_on_front');
if($homepage == $post_id && get_post_status(get_post_meta($post_id, 'featured_article', true)) == 'publish') {
// only fires during save_post hook if Home was just saved AND the chosen Article is published
$exclude = get_post_meta($post_id, 'featured_article', true); // save the Article ID to exclude from the query (below) that removes Featured status from other Articles
update_post_meta($exclude, 'featured_article', 1); // check the Featured Article's checkbox
} elseif(get_post_type($post_id) == 'article' && (get_post_meta($post_id, 'featured_article', true) == 1 || get_post_meta($homepage, 'featured_article', true) == $post_id)) {
// if an Article has either its Featured checkbox is checked, or it's selected on Home
$exclude = $post_id; // save the Article ID to exclude from the query (below) that removes Featured status from other Articles
update_post_meta($exclude, 'featured_article', 1); // check Article's checkbox (in case scheduled Article is set from Home)
update_post_meta($homepage, 'featured_article', $post_id); // update Home selection
if($post->post_status != 'publish') { // don't remove Featured status from other Articles unless the Article is published
return;
}
} else {
return;
}
// Unset all Featured Articles except the current one that's being saved or published
$featured_articles = new WP_Query(array(
'post_type' => 'article',
'post__not_in' => array($exclude),
'meta_query' => array(array(
'key' => 'featured_article',
'value' => 1,
'compare' => '='
)),
'fields' => 'ids'
));
$featured_article_ids = $featured_articles->posts;
foreach($featured_article_ids as $f) {
update_post_meta($f, 'featured_article', 0);
}
}
add_action('save_post', 'allow_only_one_featured_article', 10, 2);
add_action('publish_article', 'allow_only_one_featured_article', 10, 2);
Hit the same bug on default shop page as described. Then discovered this related post under support and was able to configure working solution…
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
if( get_field('about_this_product_category', $taxonomy . '_' . $term_id) ) {
the_field( 'about_this_product_category', $queried_object );
};
A quick update on that this bug still exist in the latest version (5.1.5).
Still hoping that this will get fixed.. ..or should I start considering other solutions to get around the problem? Anyone?
Been fiddling with this, and it looks promising, but there is one major issues that I have found.
If you are for example setting up the 3 rows flexible content row, you will add 3 new flexible content inside (one for each column)
Now, after you add blocks to each column, it’s possible to drag them up and down inside their own column (ie their own flexible content field). But in a real drag and drop scenario we would want to move every block anywhere – even between columns.
See this gif that illustrates the problem:
The question is, would this even be possible to do with ACF?
I actually did that here: http://energycoalition.org/energy-architects-in-action/
in the add_marker portion I updated it to this:
/*
* add_marker
*/
function add_marker( $marker, map ) {
// var
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
// create marker
var marker = new google.maps.Marker({
position : latlng,
map : map,
icon: '...'
});
// add to array
map.markers.push( marker );
// if marker contains HTML, add it to an infoWindow
if( $marker.html() )
{
// create info window
liTag=$("body ul.utilities").find("[data-lat='" + $marker.attr('data-lat') + "']");
// console.log(liTag);
// show info window when marker is clicked
$(liTag).click(function() {
infowindow.setContent($marker.html());
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent($marker.html());
infowindow.open(map, marker);
});
// close info window when map is clicked
google.maps.event.addListener(map, 'click', function(event) {
if (infowindow) {
infowindow.close(); }
});
}
}
I use to separate loops, one to output the list items, and one for the map. In the list items I add the latitude to the LI itself
Ok I think I’ve solved the solution (thanks to James from support too), leaving the answer here for anyone else, I used the documentation here to support it and :
In the ACF back-end I changed the choices like this:
January : January to 1 : January
February: February to 2 : February
Changing the key to a numeric value for sorting later. Now in the code I did this:
<?php
$args = array(
'post_type' => 'activities',
'posts_per_page' => -1
);
$query = new WP_Query( $args );
?>
<?php
$data;
// Create array of posts and fields
$myposts = get_posts( $args );
foreach ( $myposts as $key => $post ) : setup_postdata( $post );
$data['locations'][] = get_field('location');
$data['activity'][] = get_field('activity_type');
$data['difficulty'][] = get_field('difficulty');
// To sort months by the key value (not the label) get the field object - choice
// then grab the values like above
$monthField = get_field_object('availability');
$monthValue = get_field('availability');
// Get months, iterate through the choices
foreach($monthField as $month) {
$monthField['choices'][$monthValue] = $month;
}
endforeach;
// Omit duplicate results
foreach($data as $key => $value) {
$data[$key] = array_unique($data[$key]);
}
// sorted by alphabet
natsort($data['locations']);
natsort($data['difficulty']);
natsort($data['activity']);
// sorted by the key
ksort($monthField['choices']);
wp_reset_postdata();
?>
And the html:
<select name='month'>
<option value='' disabled selected>Choose Month</option>
<?php
foreach($monthField['choices'] as $month) {
echo "<option value='{$month}'>{$month}</option>";
}
?>
</select>
Using the field object and using ksort solved the problem here, tested and seems to work well.
Image Reference:
http://i.imgur.com/jKToQir.png
http://imgur.com/40D4ikr
I got some stuff working after playing around for awhile. First, here’s my current test setup—the flexible content has two different image uploads right now, one that spits out an image only, and another that spits out an image wrapped in some HTML that looks like a browser window.
And here’s the code I’m using to have it spit it all out:
<?php if( have_rows('project_content') ): ?>
<?php while( have_rows('project_content') ): the_row(); ?>
<?php // Normal Image Content Block
if( get_row_layout() == 'content_image' ): ?>
<?php // Vars
$contentImage = get_sub_field('image');
echo '<figure><img src="'. $contentImage['url'] .'" alt="'. $contentImage['alt'] .'" /></figure>'
?>
<?php endif; ?>
<?php // Browser Image Content Block
if( get_row_layout() == 'content_image_browser' ): ?>
<?php // Vars
$browserImage = get_sub_field('image_browser');
$browserLabel = get_sub_field('image_browser_label');
echo '<figure class="browser"><div><span></span><span></span><span></span></div><img src="'. $browserImage['url'] .'" alt="'. $browserImage['alt'] .'" /><figcaption>'. $browserLabel . '</figcaption></figure>'
?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Hope that helps you out! It did the trick for me. Now I’m just going to be following that same template and adding other content block types.
I am in the same boat here. I just upgraded to Pro and am trying to use Flexible Content for the first time and not having any luck. Eliot, is there anyway you can post the exact code you used from the demo video? I think that would lend a lot of help with syntax and how to query everything properly.
Coming back to this and still having trouble… This is my current code:
$author_id = get_the_author_meta( 'ID' );
$field_name = get_field("cbr7_review_total", $author_id);
$value = get_field('$cbr7_review_number', $post->ID);
update_field( $field_name, $value, $author_id);
I agree there has to be a setting for this. I think it should check if that field is actually translated in the options group settings. If so, the way it works now is good. If not, it should always fall back to the original language.
Quick fix for people that need it working now:
Add this just before your get_field() function, where ‘en’ is your default language. Call the filter again with the current language to reset it again, so it wont affect pages and stuff.
// add this
add_filter('acf/settings/current_language',function() {
global $sitepress;
return $sitepress->get_default_language();
});
// this is already in your code
$my_field = get_field('my_field', 'option');
// reset to original language
add_filter('acf/settings/current_language',function() {
return ICL_LANGUAGE_CODE;
});
Hi
I happen to have the exact same issue as you. Your solution looks good but my question is where do you get that “$params” array from?
Thanks!
Hello to all,
I had a response from OVH. They did some request in curl from their servers. Here are the results :
~$ curl -i http://connect.advancedcustomfields.com/index.php
400 Bad Request
nothing is returned
~$ curl -i http://connect.advancedcustomfields.com/index.php?a=get-info&p=pro
There are some data returned but it ends with a HTTP/1.1 400 Bad Request
~$ curl -i http://assets.advancedcustomfields.com/add-ons/add-ons.json
HTTP/1.1 200 OK
Everything is fine.
I did those test in my terminal and get the same results. On OVH point of view the problem comes from ACF server.
Using update field does not work for date (it works for string).
So the solution I’ve put in place is :
$this->birthdate = date( "Ymd", $this->birthdate );
update_post_meta ($this->ID, 'birthdate', $this->birthdate);
update_post_meta ($this->ID, '_birthdate', 'field_53e11dd3841f6'); // CONSTANT KEY
After working with WP All Import support, it appears that the problems that I’m seeing have something to do with a MySQL server misconfiguration and not with the plugin itself. I can’t reproduce these errors on their testing server and it seems neither can they.
If we can figure out what the problems is I will post it here just in case anyone else is having similar problems.
Have you tried using "
?
I’m having a similar issue, ACF strips double quotes when they’re entered into a textbox by the client. Doesn’t matter if the “New Lines” option is set to “Automatically add paragraphs, Automatically add <br>, or No Formatting.” The solution is to use single quotes but I really wish that wasn’t the case.
And to possibly help with your particular case, @michael-b, have you tried using a “typographer” or “curly” quote instead? Either the entity itself (”) or alphanumeric version (”
)
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.