Thank you so much good Sir, got me out of a hole that one, knew I was doing something wrong
yes I did, here is the code I am using.
function change_post_taxonomy_44582( $post_id ) {
if ( empty($_POST['acf']) ) {
return;
}
// get term id from $post_id (only 1 value is allowed, so it returns 1 value only)
$stored_role = wp_get_post_terms($post_id, 'asproducts_cats');
// get submitted value from acf form
$posted_roles = $_POST['acf']['field_59154e83efb0e'];
// get term_id for the submitted value
$term_id = get_term_by( 'name', $posted_roles, 'asproducts_cats' );
// if stored value is not equal to posted value, then update terms
if ( $stored_role[0] != $posted_roles ) {
wp_set_object_terms( $post_id, $term_id->term_id, 'asproducts_cats' );
}
}
add_action('acf/save_post', 'change_post_taxonomy_44582', 20);
Also have a look here https://support.advancedcustomfields.com/forums/topic/conditional-logic-using-taxonomy-field/page/4/
A nice chap helped me out with this. Shout if you are still having issues
Keith
Thanks for your time, very much appreciated, at least we now have an answer and I learnt something
Am I being dumb, can see the PM?
ok, having read through what you have put several times so its clear in my head I have to left of the : put the id of the term, Ie 36 : Embedded Systems. I made the change above to the code to reflect it as ID and it is still not setting the taxonomy on save. So I am now very much lost, is this the way I defined the custom taxonomy?
they do, I copied them over. Should I be using the : ?
Hi Beee
Sorry its taken me so long to get back to you, got swamped at work then the weekend happened.
My apologies if I come across a bit thick here. I am not very advanced when it comes to WordPress backend devloping, I am learning as I go.
In the ACF radio field I have four product types, i.e. Embedded systems, In the product category I have same. I have not used any kind of number system. Is that what I need to do?
Aga
Thanks for the reply Beee. I might be a bit thick here, but I don’t see options on a radio field to return string or ID. Am I missing something?
Hi I am trying to get either of the two above examples to work and seem to be failing> I am not sure what is going wrong. This is the code
function change_post_taxonomy_44582( $post_id ) {
// bail if no ACF data
if ( empty($_POST['acf']) ) {
return;
}
// get term id from $post_id (only 1 value is allowed, so it returns 1 value only)
$stored_role = wp_get_post_terms($post_id, 'asproducts_cats');
// get submitted value from acf form
$posted_roles = $_POST['acf']['field_59154e83efb0e'];
// get term_id for the submitted value
$term_id = get_term_by( 'name', $posted_roles, 'asproducts_cats' );
// if stored value is not equal to posted value, then update terms
if ( $stored_role != $posted_role ) {
wp_set_object_terms( $post_id, $term_id->term_id, 'asproducts_cats' );
}
}
add_action('acf/save_post', 'change_post_taxonomy_44582', 20);
Have I done something wrong?
Hi James
Further to my last post, I finally made it work. I tried using the code on that page yesterday, but I must of been tired, because this morning and made it work. There may of been a small amount dancing around the room
(see below)
<ul class="col-md-6">
<?php $i = 0; $j = count( get_field('suppliers_table') );
$repeater = get_field('suppliers_table');
$order = array();
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['company'];
}
array_multisort( $order, SORT_ASC, $repeater );
if( $repeater ): ?>
<?php foreach( $repeater as $i => $row ): ?>
<li class="supplier_link">
<a href="<?php echo $row['company_url']; ?> "target="_blank"><?php echo $row['company']; ?></a>
</li>
<?php if ( ( $i + 1 ) == ceil($j / 2) ) echo '</ul><ul class="col-md-6">'; ?>
<?php $i++; endforeach; ?>
<?php endif; ?>
</ul>
Only been at this fro two days.
I still don’t understand why the function in functions.php is not working. Is there anyway to see if anything is conflicting with it?
Hi James
Thanks for your reply, I did look at this page, It is the key, yet the function is not working. Is there anyway to build a sort into the two column loop I posted?
Sorry i am kind of newbie with php.
Keith
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.