Home › Forums › Backend Issues (wp-admin) › Empty ACF values in wp-admin
Hi.
Site owner imported description, meta title and meta keywords values with WP All Import into ACF fields that were assigned to WooCommerce categories.
The result is that this imported values are shown in frontend with this code
<?php
global $woocommerce, $woocommerce_loop, $product;
$category = get_queried_object();
$ct = $category->name;
$catid = $category->term_id;
the_field('description', $catid); ?>
but not visible in wp-admin
Here is Group of Fields
For testing purposes I’ve created my new ACF field, filled it and put in frontend. It works as expected (I see value both in frontend and in backend).
About DB:
My New field is in wp_options table (piece of dump)
INSERT INTO
wp_options` VALUES(“13198”, “product_cat_15_description2”, “Описание от Devise”, “no”);
INSERT INTO wp_options
VALUES(“13199”, “_product_cat_15_description2”, “field_5b30f2f1fde5f”, “no”);`
but problematic fields are in wp_postmeta
INSERT INTO
wp_postmeta` VALUES(“101229”, “795”, “_wp_page_template”, “default”);
INSERT INTO wp_postmeta
VALUES(“101228”, “795”, “description”, “<h2>Трубы чугунные ВЧШГ ГОСТ 9583-75: технические характеристики</h2><p>text</p>”);
INSERT INTO wp_postmeta
VALUES(“101227”, “795”, “_description”, “field_5ac67e4bbc4ff”);`
The question is how can I repair problematic fields to make them show in backend too.
I’m trying
global $woocommerce, $woocommerce_loop, $product;
$category = get_queried_object();
$catid = $category->term_id;
foreach ($catid as $c) {
update_field( ‘field_5ac67e4bbc4ff’, get_post_meta( $c, ‘description’, true ), $c );
}
but it doesnt work
If the field group did not exist before the import then you can’t make these fields appear by creating a new field group.
And it appears that the fields were not imported to the taxonomy/terms but were imported to the posts. This is why the values do not appear when editing the product category. Since these values are not associated with the term you cannot make them appear in the admin. Quite honestly, I don’t know how they are appearing in the front end.
Importing into a term is a special process http://www.wpallimport.com/documentation/taxonomies/import-taxonomy-meta/
in your code
global $woocommerce, $woocommerce_loop, $product;
$category = get_queried_object();
$ct = $category->name;
$catid = $category->term_id;
the_field('description', $catid); ?>
the value of $catid
is wrong. In order to get a value from a field for the term it would need to be the_field('description', 'term_'.$catid);
so what you are actually seeing on the front end is the values in post meta that are related to a post with the ID that is equal to whatever that the ID of the term is.
There really isn’t an easy solution to this if there is a solution at all. If there is I can’t think of one.
Is it possible to fix if with update_meta ?
Support’s answers about problem:
This is a common occurrence when fields are imported from an external source to the database. The issue occurs because imported field values lack a field reference to format the value of the field so that it can properly load on the admin UI. To fix this, you will need to pass the values through the update_field() function. Please take a look at the following resource page for more info on this: https://www.advancedcustomfields.com/resources/update_field/
and
ACF saves term data using a post id parameter containing the string ‘term_’ and thus you will need to ensure that you factor this in while coming up the code. Please note that our support scope does not extend to the provision of custom code snippets but it looks like you are on the right track. I would suggest that you debug your code line by line to ensure that it is returning the expected data. Please take a look at our debugging tutorial on this page: https://www.advancedcustomfields.com/resources/debug/
The problem is that the values are stored in the wrong place, associated with a post instead of a term. Because WPAI was used for the import the fields have the correct key associations. So the first reply, while it can cause issues is not really the problem.
What you would need to do to correct the situation using the data as it exists.
1) Get all of the products
2) Figure out what product category these values were supposed to be applied to
3) Get these fields from the product
4) update the field using the correct term id "term_{$term->term_id}"
The problem here is going to be figuring out #2.
– What categories is the product assigned to?
– Is there more than one category?
– Where the values imported to posts more than one time, i.e. where the same values added to multiple posts in the category?
– If the product is in multiple categories then which category were the values really meant for?
Because of these questions, and the additional questions that the answers would probably create, it’s really hard to give any meaningful way to resolve the problem.
If this was me I would create a field group for the categories and then I’d create to proper import to import these meta values to the categories and I would just ignore the data that was created in the wrong way…. or find an way to just delete it all from the database, rather than try to transform the data that is stored improperly.
The topic ‘Empty ACF values in wp-admin’ 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.