Home › Forums › General Issues › Duplicate MetaKeys for Boolean in ACF_LITE
I’m using ACF_LITE and a php exported acf.php in my LIVE environment. I use a TEST environment and everything works well there.
In LIVE, though, especially with a boolean value, I am unable to change the value of the boolean field when editing the post. It acts as if it updated but the value doesn’t change.
I am able to run a query like this and see why it seems to not update:
select * from wp_postmeta where post_id = 136 and meta_key = 'is_auction';
The result shows that there are multiple records for this meta_key. Why is it doing this?
i’ve just experimented by placing TEST into ACF_LITE mode and have it include the acf.php. the issue cannot be duplicated that way.
then i tried pointing the database to LIVE and i WAS able to recreate the duplicate meta_key.
so it’s got something to do with the database. but where do i start?
i’ve tried disabling the other plugins. the only fields that are duplicating meta_keys are those that are in the auction_ group. the other booleans and other field groups are working as expected.
i’m running out of things to try.
in narrowing it down, i can recreate using just this as my acf.php:
<?php
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_experience-post-fields',
'title' => 'Experience Post Fields',
'fields' => array (
array (
'key' => 'field_52bc856a5d6b9',
'label' => 'Is Auction',
'name' => 'is_auction',
'type' => 'true_false',
'instructions' => '',
'message' => '',
'default_value' => 0,
)),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'experience',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
i have backed up all the tables from LIVE. in restoring them one-by-one to TEST, i found that the problem must exist in the table:
wp_postmeta
if i restore the TEST wp_postmeta, i cannot recreate the issue. if i restore the LIVE wp_postmeta, i CAN recreate the issue.
i did find (probably due to the ACF_LITE) that many postmeta records exist with meta_id of 0. i tried deleting all of these, but that is not the solution. that just causes data loss.
after restoring my backup, i’m again facing the problem neatly in a corner and completely out of my reach.
what in wp_postmeta could cause this duplication of meta_keys?
my last post got me wondering why there wasn’t an auto_incrementing field. that seemed highly unusual; in fact, according to this…wp_postmeta should not have any 0’s in the meta_id field since it is supposed to be an auto-incrementing field. i lost my indexes somewhere.
https://codex.wordpress.org/Database_Description#Table:_wp_postmeta
and, adding the indexes back fixes it! here are the queries i used if it helps anyone that somehow lost their indexes as well.
alter table wp_postmeta change column meta_id id integer unsigned, add column meta_id integer unsigned primary key auto_increment first;
update wp_postmeta set meta_id = meta_id + 9000; -- more than the number of rows in the table
update wp_postmeta set meta_id = id where id <> 0;
alter table wp_postmeta drop column id;
alter table wp_postmeta add index (meta_key), add index (post_id);
The topic ‘Duplicate MetaKeys for Boolean in ACF_LITE’ is closed to new replies.
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.