This is indeed a problem and I hope it’ll be fixed soon. I’m quite dependent on both PTO and ACF’s page/post objects. Interestingly enough, my problem didn’t start until I added a specific post type for the field, anyone else experience the same thing? Might lead to a clue as to what the issue is..
on a production website, running in older versions (WordPress 3.9.2 // Advanced Custom Fields by Elliot Condon version 4.3.8 // WPML Multilingual CMS by ICanLocalize version 3.1.6 // WPML Translation Management by ICanLocalize version 1.9.5), everything works fine:
### Environment ###
WC Version: 2.1.12
WC Database Version: 2.1.12
WP Version: 3.9.2
WP Multisite Enabled: No
Web Server Info: nginx/1.1.19
PHP Version: 5.3.10-1ubuntu3.13
MySQL Version: 5.5.35
WP Memory Limit: 256 MB
WP Debug Mode: No
WP Language: Default
WP Max Upload Size: 32 MB
PHP Post Max Size: 32 MB
PHP Time Limit: 300
PHP Max Input Vars: 1000
SUHOSIN Installed: No
WC Logging: Log directory is writable.
Default Timezone: Default timezone is UTC
fsockopen/cURL: Your server has fsockopen and cURL enabled.
SOAP Client: Your server has the SOAP Client class enabled.
WP Remote Post: wp_remote_post() was successful – PayPal IPN is working.### Plugins ###
Installed Plugins: Advanced Custom Fields: Date and Time Picker by Per Soderlind version 2.0.16
Advanced Custom Fields: Repeater Field by Elliot Condon version 1.1.1
Share Buttons by AddToAny by AddToAny version 1.3.5
Adminimize by Frank BΓΌltge version 1.8.4
Advanced Custom Fields: Limiter by Atomic Smash – David Darke version 1.1.0
Advanced Custom Fields by Elliot Condon version 4.3.8
Akismet by Automattic version 3.0.2
Contact Form 7 by Takayuki Miyoshi version 3.9.1
Custom Favicon by Dreams Online Themes version 1.0.2
Google Analytics for WordPress by Joost de Valk version 4.3.5
Google XML Sitemaps by Arne Brachhold version 4.0.7
Latest Custom Post Type Updates by David Wood version 1.3.0
Simple Image Sizes by Rahe version 3.0
WPML Multilingual CMS by ICanLocalize version 3.1.6
Soliloquy Thumbnails Addon by Thomas Griffin version 1.0.4.1
Soliloquy by Thomas Griffin version 2.3.4
User Role Editor by Vladimir Garagulya version 4.14.4
WooCommerce Gateways Country Limiter by OnTheGoSystems version 1.0.3
Woocommerce Adwords Conversion Tracking by VΓctor FalcΓ³n version 1.0.1
WooCommerce MailChimp by Adam Anderly version 1.3.1
WooCommerce Multilingual by ICanLocalize version 3.3.2
WooCommerce by WooThemes version 2.1.12
WooCommerce HeidelpayCw by customweb GmbH version 1.0.120
wpMandrill by Mandrill version 1.33
WPML CMS Nav by ICanLocalize version 1.4.4
WPML Media by ICanLocalize version 2.1.5
WPML Sticky Links by ICanLocalize version 1.3.4
WPML String Translation by ICanLocalize version 2.0.6
WPML Translation Management by ICanLocalize version 1.9.5
Found the answer on Stack Exchange.
In order for this to work you need to reset each query with
wp_reset_query()
Hi @Elliot Condon
You confused the_content with another ACF field, the default editor was removed by me in functions.php.
Attached is another screenshot after I got it back:
– Ido
After some tests, I realize that in group fields, ACF create fields named “field_***” (used for post_name) but after saving post_name become “field-***”.
The reason is that wp_insert_post() (used for creating field) sanitize post_name with sanitize_title function (check wp-includes/post.php on line 3189).
To prevent this, I have to add a filter to return original post_name.
In advanced-custom-fields-pro/api/api-field.php, I add in function acf_update_field() on line 839 :
add_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100, 3 );
just before :
$field['ID'] = wp_insert_post( $save );
and remove that filter just after saving :
remove_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100 );
And after acf_update_field :
function acf_update_field_sanitize_title ( $title, $raw_title, $context ) {
return $raw_title;
}
It seems to work for meβ¦
Note :
if you donβt want to alter ACF sources, you can add this to your functions.php :
function acf_update_field_sanitize_title ( $title, $raw_title, $context ) {
return $raw_title;
}
// add filter for sanitize_title
add_filter( 'acf/update_field', function ( $field ) {
add_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100, 3 );
return $field;
}, 10, 1 );
// remove filter for sanitize_title
add_filter( 'wp_unique_post_slug', function ( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
remove_filter( 'sanitize_title', 'acf_update_field_sanitize_title', 100 );
return $slug;
}, 10, 6 );
I had a similar problem, but it was not only on upgraded fields ; but also on new created fields ; nothing saved.
I found that it was the post_name which cause problem.
β post_excerpt is a readable slug
β post_name is a string starting with “field-”
If I change post_name to start with “field_” ; I was able to save my data.
I just run this SQL query and everything seems to work :
UPDATE wp_posts SET post_name = CONCAT( 'field_', SUBSTR( post_name, 7 ) ) WHERE post_type = "acf-field" && post_name LIKE "field-%"
Fantastic, I had missed that. Thank you.
As a more general question, if someone has built a third party add-on does that reduce the likeliness that it will ever be built into the ACF core? I’m very grateful that people build these add-ons, but I’d be interested to know what parameters are considered before something is built into ACF as oppose to someone building it as an add-on.
http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/ Might answer your questions.
I’d say that means that if you use it in a theme, that is the latest version they can get unless they buy their own license, then they can get updates.
I’m not a lawyer. So I might be misunderstanding.
A clearer version of this question would be:
When using acf_form to create new posts, can I use a Select field to categorize a post? In addition to that, is it possible to use field (maybe a text area) to tag posts?
Hey guys
Thanks for all your great work on this issue. I’ve just added some new logic to help avoid this problem. It doesn’t seem to effect everyone and I can’t replicate it on my end, but I’m quite confident that the next version will solve the issue.
I’ve created a new function which updates an inputs val, and only triggers the change event if the new val is different to the old val.
Good work on the above hot fixes,
Cheers
E
Hey Guys,
I figured out the issue. Basically, in my previous post I had the greater than & less than comparison switched AND also my filter was not properly string replacing both sql where statements. Here’s the code I have working now, hopefully it helps someone out there:
WP_Query args:
//Serial# Meta Query $args = array( 'post_type' => 'manual', 'numberposts' => - 1, 'suppress_filters' => false, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'files_%_start_range_num', 'value' => intval( $_GET['s'] ), 'type' => 'NUMERIC', 'compare' => '<=' ), array( 'key' => 'files_%_end_range_num', 'value' => intval( $_GET['s'] ), 'type' => 'NUMERIC', 'compare' => '>=' ) ), );
Filter:
// custom filter to replace '=' with 'LIKE' // see: http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/ function acf_posts_where( $where ) { $where = str_replace( "meta_key = 'files_%", "meta_key LIKE 'files_%", $where ); return $where; } add_filter( 'posts_where', 'acf_posts_where' );
I join the request of @chris Lanphear, but it would be even better if the usability of Flexible content field would be improved, so it will work similiar to the Site Origin plugin.
Okay, I’ve solved the map issue by removing my enqueued script and loading the api with ajax for my map.
if( typeof google === 'undefined' )
{
jQuery.getScript('https://www.google.com/jsapi', function(){
google.load('maps', '3', { other_params: 'sensor=false& libraries=places', callback: function(){
//map code goes here
}});
});
}
Would be great to have acf.add_action('ready append', function( ){
working though
ok i switched to relationship fields and wanted to do same thing
i did it by filtering the query so for anybody who wants to do the same thing here is the code
<?php
function my_post_object_query( $args, $field, $post )
{
// modify the order
$args[‘post_status’] = array(‘publish’);
return $args;
}
// filter for every field post object
add_filter(‘acf/fields/post_object/query’, ‘my_post_object_query’, 10, 3);
// filter for every field relationship
add_filter(‘acf/fields/relationship/query’, ‘my_post_object_query’, 10, 3);
From where you created the custom field groups by code or from the back-end.
1. back-end : –
you can see the option to add the required field
2. through code : –
Here is an example which i created
`array (
‘key’ => ‘field_53ba5630e48e8’,
‘label’ => ‘Email’,
‘name’ => ’email’,
‘type’ => ’email’,
‘instructions’ => ‘Please enter your email’,
<strong>’required’ => 1,</strong>
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
)
You can see the required field value.
Yes that’s correct. You will want to do the meta query on the posts ID, not the title π
This was helpful, and took me awhile to get.
I’m doing something similar.
I have a list of staff members as custom post type
Each staff member makes a monthly book pick – also a custom post type called staffpicks
ACF is running on staffpicks with a custom object field relating back to the staff member who picked it.
When using the post object field – even though the post object field will show the title of the post in the select box (which is convenient…thanks), it’s actually saving the post ID of that related post object in the database.
So when we run the meta query we have to use a value of post id – not the title of that post.
Am i getting that right?
You need to include this on your page:
<style type="text/css">
.acf-map {
width: 100%;
height: 400px;
border: #ccc solid 1px;
margin: 20px 0;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
(function($) {
/*
* render_map
*
* This function will render a Google Map onto the selected jQuery element
*
* @type function
* @date 8/11/2013
* @since 4.3.0
*
* @param $el (jQuery element)
* @return n/a
*/
function render_map( $el ) {
// var
var $markers = $el.find('.marker');
// vars
var args = {
zoom : 16,
center : new google.maps.LatLng(0, 0),
mapTypeId : google.maps.MapTypeId.ROADMAP
};
// create map
var map = new google.maps.Map( $el[0], args);
// add a markers reference
map.markers = [];
// add markers
$markers.each(function(){
add_marker( $(this), map );
});
// center map
center_map( map );
}
/*
* add_marker
*
* This function will add a marker to the selected Google Map
*
* @type function
* @date 8/11/2013
* @since 4.3.0
*
* @param $marker (jQuery element)
* @param map (Google Map object)
* @return n/a
*/
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
});
// add to array
map.markers.push( marker );
// if marker contains HTML, add it to an infoWindow
if( $marker.html() )
{
// create info window
var infowindow = new google.maps.InfoWindow({
content : $marker.html()
});
// show info window when marker is clicked
google.maps.event.addListener(marker, 'click', function() {
infowindow.open( map, marker );
});
}
}
/*
* center_map
*
* This function will center the map, showing all markers attached to this map
*
* @type function
* @date 8/11/2013
* @since 4.3.0
*
* @param map (Google Map object)
* @return n/a
*/
function center_map( map ) {
// vars
var bounds = new google.maps.LatLngBounds();
// loop through all markers and create bounds
$.each( map.markers, function( i, marker ){
var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
bounds.extend( latlng );
});
// only 1 marker?
if( map.markers.length == 1 )
{
// set center of map
map.setCenter( bounds.getCenter() );
map.setZoom( 16 );
}
else
{
// fit to bounds
map.fitBounds( bounds );
}
}
/*
* document ready
*
* This function will render each map when the document is ready (page has loaded)
*
* @type function
* @date 8/11/2013
* @since 5.0.0
*
* @param n/a
* @return n/a
*/
$(document).ready(function(){
$('.acf-map').each(function(){
render_map( $(this) );
});
});
})(jQuery);
</script>
Then use this code when you want to display the map
<?php
$location = get_field('access_map');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
</div>
<?php endif; ?>
Complete documentation is here: http://www.advancedcustomfields.com/resources/google-map/
Great news! We have progress! I took a stab at delving into the ACF core JS files and I think I have found the problem.
The issue lies within the input.js
that spits out all the javascript for ACF to function. I suspect the same code is within google-map.js
but I didn’t want to screw around with enqueueing it and de-registering the rest of them.
I started by commenting out all the JS regarding Gmaps, and slowly uncommenting it out to see where the weird reload was coming from. This narrowed it down to this function call.
Around line 4105, you will find the acf/setup_fields function. Here is where the problem lies.
/*
* acf/setup_fields
*
* run init function on all elements for this field
*
* @type event
* @date 20/07/13
*
* @param {object} e event object
* @param {object} el DOM object which may contain new ACF elements
* @return N/A
*/
acf.add_action('ready append', function( $el ){
//vars
var $fields = acf.get_fields({ type : 'google_map'}, $el);
// validate
if( !$fields.exists() )
{
return;
}
// validate google
if( typeof google === 'undefined' )
{
$.getScript('https://www.google.com/jsapi', function(){
google.load('maps', '3', { other_params: 'sensor=false&libraries=places', callback: function(){
$fields.each(function(){
acf.fields.google_map.set({ $el : $(this).find('.acf-google-map') }).init();
});
}});
});
}
else
{
$fields.each(function(){
acf.fields.google_map.set({ $el : $(this).find('.acf-google-map') }).init();
});
}
});
The variable and the first statement are harmless. The if statement just checks to see if any google map fields exist. The issue is further narrowed to the “Validate Google” part of the function. If you comment out that whole if/else statement, the field will not load, however, no warning will be triggered.
I’m struggling to see how the else statement fits into the picture as well. At first I thought it was for rendering fields after the initial first map, but adding console comments show that the if
part of the function is called for each map field regardless of other maps on the page.
If you comment out the if
part of the function, and just leave the else
(removing the “else” and curly brackets so it triggers correctly), a google is undefined
error is thrown and the map doesn’t load. However, there is no warning when navigating away.
I feel like I’m rambling now, but the issue lies within the if
statement. I have a feeling that this is because something in the pages <form>
element is being altered by the rendering of the map, triggered from this location. This triggers the warning message when trying to navigate away from the page.
I’ve examined the input.js file from v4 (current on repo) and there doesn’t seem to be a lot of differences. There was the call in v4 to a function called is_clone_field
but adding that to v5 returned undefined.
So this is where my knowledge ends. I also feel like I may be rambling π
I’m tagging a couple people so hopefully this can get resolved! It’s a very strange error but it definitely needs to be addressed. One of the great things about ACF is the awesome user interface as well as the well thought out UX. This bug is a game-breaker on that front though. Clients shouldn’t feel like all their work is lost every time they want to navigate away from one of these pages. It’s a false sense of unease that shouldn’t be there.
Hope this helps!
@fatbeehive @Elliot Condon
@bobz @aditron @strommerm
Hi SaskiaB! I solved it by adding a hidden input field to the form.
So in my page:
$bio_args = array(
'post_id' => 'new_artist',
'field_groups' => array( 55 ),
'submit_value' => 'Submit my Bio',
// 'return' =>
'html_after_fields' => '<input type="hidden" name="post_type" value="frp_artist">'
);
?>
<?php acf_form( $bio_args ); ?>
Then in my functions:
function wnc_bio_frontend( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new_artist' )
{ return $post_id; }
// Create a new post
$tax_actors = array(
$_POST['fields']['field_5439adfebbbcb'],
);
$post = array(
'post_status' => 'pending',
'post_title' => $_POST['fields']['field_5439aa052a606'],
'post_type' => $_POST['post_type'],
'tax_input' => $tax_actors,
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'wnc_bio_frontend' );
Notice the “post type” hidden field. I hope that helps!
ok it works with this below, could you please now have a look at my second question please ? thanks
function my_acf_admin_head()
{
?>
<script type="text/javascript">
jQuery(function($){
$('select').on('change', function() {alert( this.value );})
});
</script>
<?php
}
add_action('acf/input/admin_head', 'my_acf_admin_head');
…my second question would be:
I get the WP users in your Dropdown field by login, how could i retrieve user ID onchange in the list ?
thanks
If anyone else is having issues here, the specific fix that worked for me is:
// $(document).trigger('acf/setup_fields', $("#"+ formID) );
acf.do_action('ready', $("#"+ formID) );
Wrap your acf output calls with a conditional statement using post_password_required()
, example here:
http://codex.wordpress.org/Using_Password_Protection#Protect_Custom_Fields
http://codex.wordpress.org/Function_Reference/post_password_required
jacobnollette,
Thanks for the swift reply.. I did figure out what you meant and went into the db and upped the field length to 255. Will this get overwritten when wordpress updates, though? And is that the only change required? Did you not find that there is also code within wordpress that truncates those based on an assumption of a length of 64?
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.