Hi John, that works fine.
But, is there a way for BULK changing? I got round 20000 posts, that will be a big work, open and re-save them.
Any Suggestion?
Cheers,
Denis
Hello John,
is it correct that I need to save the Post twice to the the SLUG changed?
Or am I doing something wrong?
function modify_post_slug($post_id) {
$artist = get_field('artist', $post_id);
$album = get_field('album', $post_id);
$datum = get_field('datum', $post_id);
$ref = $artist.' '.$album.' '.$datum;
if ($ref) {
$post = get_post($post_id);
$slug = sanitize_title($ref);
$post->post_name = $slug;
remove_filter('acf/save_post', 'modify_post_slug');
wp_update_post($post);
add_action('acf/save_post', 'modify_post_slug');
}
}
add_action('acf/save_post', 'modify_post_slug');
Cheers,
Denis
I think I made it.
function my_copy_date_filter( $post_id ) {
$post_type = get_post_type( $post_id );
if ( $post_type != 'spot' ) {
return;
}
$location = get_field( 'spot_location', $post_id );
if( $location[ 'lat' ] && $location[ 'lng' ] ) {
update_post_meta( $post_id, 'spot_coordinates', $location[ 'lat' ].','.$location[ 'lng' ] );
}
if( $location[ 'address' ] ) {
update_post_meta( $post_id, 'spot_address', $location[ 'address' ] );
}
if( $location[ 'state' ] ) {
wp_set_object_terms($post_id, $location[ 'state' ], 'bundesland', false);
}
if( $location[ 'city' ] ) {
wp_set_object_terms($post_id, $location[ 'city' ], 'ort', false);
}
if( $location[ 'post_code' ] ) {
wp_set_object_terms($post_id, $location[ 'post_code' ], 'postleitzahl', false);
}
}
add_filter( 'acf/save_post', 'my_copy_date_filter', 20 );
It inserts new Terms related to the post π
So you want to create a taxonomy based on the location added to a post?
Right!
Is the new term supposed to be added to the post?
Yes, the terms should be stored in the post. Term_relation or what it is called.
How will this be used?
It will be shown on the single post and so the visitor can click on it and see what other posts are in the state, city or post_code.
So, I just want to add the google Map details, to my existing taxomonies – under the hood, automatic, the User does not have to do anything.
Denis
Hello,
Sorry for being not clear enough.
I try again, the use only should select a spot on the google map.
Under the hood (function.php) I want extract the CITY, POSTCODE and STATE from the ARRAY and put this values in the taxonomies I created with CPT UI.
The use does only need to spot a place on the map.
Cheers,
Denis
Hello John,
thanks so far, but how does it work if I use taxonomies created with CPT UI plugin?
Also, I donβt want to show the taxonomy in the post. It should work under the hood. Will I need another fieldset?
Right now I am a little confused π
With your help I made it this far. But/where can I find the Term ids?
function my_copy_date_filter( $post_id ) {
$post_type = get_post_type( $post_id );
if ( $post_type != 'spot' ) {
return;
}
$location = get_field( 'spot_location', $post_id );
if( $location[ 'lat' ] && $location[ 'lng' ] ) {
update_field( 'spot_coordinates', $location[ 'lat' ].','.$location[ 'lng' ], $post_id );
}
if( $location[ 'state' ] ) {
update_field( 'spot_bundesland', $location[ 'state' ], 'term_'.$term_id );
}
if( $location[ 'city' ] ) {
update_field( 'spot_stadt', $location[ 'city' ], 'term_'.$term_id );
}
if( $location[ 'address' ] ) {
update_field( 'spot_address', $location[ 'address' ], $post_id );
}
}
add_filter( 'acf/save_post', 'my_copy_date_filter', 20 );
Greetings from Cologne,
Denis
Hey John,
I will use this solution.
Thanks a lot,
Denis
Hello John,
this works!
One ) is too much.
add_action('acf/save_post', 'save_post_type_post'), 20);
Thanks a lot.
Denis
Hey John,
when I use the code
/* ACF Custom Slug */
function my_acf_save_post( $post_id ) {
// bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// specific field value
$my_new_slug = $_POST['acf']['field_5705116adbe84'].'-'.$_POST['acf']['field_5705117fdbe85'].'-'.$_POST['acf']['field_5705118edbe86'];
$post = array(
'ID' => $post_id,
'post_name' => $my_new_slug
);
wp_update_post($post);
}
// run before ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 1);
I get an
ERROR 500 – Internal Server Error
When I used it the first time it worked…but now I get the Error 500.
Cheers,
Denis
Hey James,
I will π
Cheers,
Denis
HI John,
so I need 2 functions?
<?php
function my_acf_save_post( $post_id ) {
// bail early if no ACF data
if( empty($_POST['acf']) ) {
return;
}
// specific field value
$my-new-slug = $_POST['acf']['my-slug-part1'].'-'.$_POST['acf']['my-slug-part2'].'-'.$_POST['acf']['my-slug-part3'];
}
// run before ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 1);
?>
How will I save the $my-new-slug to the post-slug?
Is there also a filter that makes the slug like it will be done by wordpress. deleting unwanted charachters?
Cheers,
Denis
Hello James,
I did deactivate all plugins (exept ACF and CPT UI). I change the theme to Twenty Fifteen.
I did shorten the fieldnames, but the tourdates are not stored in the metagbox.
The venues are stored in the taxonomy on the right side but not in the metabox.
What else can I do?
Denis
Hello!
Any news here? Is time now in the datepicker for Pro version?
Cheers,
Denis
Hi there,
I have got the same problem in the latest pro-version. And my categories meta box is gone and I allways have to activate it again via options.
Cheers,
Denis
Hello,
my choosen datepicker (FIELD TYPE) is not selected anymore, but seems to work. And German language is destroyed, too.
Cheers,
Denis
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.