Home › Forums › Front-end Issues › ACF repeater fields not showing up before manual update
I have developed a plugin which fetches posts from another websites API. I have two post types on my local site: post1 and post2
Plugin compares post1 to post2 and syncs only the missing post2 posts from the API.
So, a new post is generated:
function insert_local_post( $local_post ) { // insert new post
$post_data = array(
'post_type' => 'post2',
'post_status' => 'private',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'post_name' => $local_post->post_name,
'post_title' => $local_post->post_title,
'post_date' => $local_post->post_date,
'post_date_gmt' => $local_post->post_date_gmt,
'post_content' => '',
);
$new_post = wp_insert_post( $post_data );
if ( $new_post ) {
update_field( 'unique_identifier', get_field( $this->local_post_identifier, $local_post->ID ), $new_post );
}
return $new_post;
}
After creating the post, post status gets changed to ‘publish’ and updating the fields is called:
$publish = array( 'ID' => $ID, 'post_status' => 'publish' );
wp_update_post($publish);
$this->update_local_fields( 'fields1', $fields, $ID);
$this->update_local_fields( 'fields2', $fields, $ID);
$this->update_local_fields( 'fields3', $fields, $ID);
For fields I have a field conf file with a hierarchical set of extra field names. Same hierarchical structure as the fields coming from the API.
Function for updating the fields:
function update_local_fields( $field_group_name, $fields, $ID ) {
foreach ( $this->field_conf[$field_group_name] as $field_key => $field_name ) {
if ( ! is_numeric( $field_key ) ) {
$this->delete_local_repeater_fields( $field_key, $ID );
$this->insert_local_repeater_fields( $field_key, $ID, $fields->$field_key, $field_group_name );
continue;
}
if ( $fields->$field_name and
( $field_name == 'taxonomy1' or
$field_name == 'taxonomy2' or
$field_name == 'taxonomy3' ) ) {
$fields->$field_name = $this->link_to_local_taxonomy_terms( $fields->$field_name );
}
update_field( acf_get_field($field_name)['key'], $fields->$field_name, $ID );
}
return;
}
The main chunk of code for creating the rows and subrows for repeater fields:
function insert_local_repeater_fields( $repeater_row_name, $ID, $fields, $field_group_name ) {
$local_repeater_name = $repeater_row_name;
if ( $fields ) {
for ( $i = 0; $i < sizeof($fields); $i++ ) {
$row_data = array();
foreach ( $this->field_conf[$field_group_name][$repeater_row_name] as $row_field ) {
if ( ! is_array($row_field) ) {
$local_row_field = $row_field;
if ( $fields[$i]->$row_field and $row_field == 'location' ) {
$fields[$i]->$row_field = $this->link_to_local_taxonomy_terms( $fields[$i]->$row_field );
}
$row_data[$local_row_field] = $fields[$i]->$row_field;
}
}
add_row(acf_get_field($local_repeater_name)['key'], $row_data, $ID);
if ( $fields[$i]->cities ) {
foreach ( $fields[$i]->cities as $city) {
$sub_row_data = array();
foreach ( $this->field_conf[$field_group_name][$repeater_row_name]['cities'] as $sub_row_field ) {
$local_sub_row_field = $sub_row_field;
if ( $city->$sub_row_field and $sub_row_field == 'location' ) {
$city->$sub_row_field = $this->link_to_local_taxonomy_terms( $city->$sub_row_field );
}
$sub_row_data[$local_sub_row_field] = $city->$sub_row_field;
}
add_sub_row( array(acf_get_field($local_repeater_name)['key'], ($i + 1), 'cities'), $sub_row_data, $ID );
}
}
}
}
}
The problem is that the fields only show up when I manually update the post and run the sync again. I have tried a million things: using keys instead of fields etc, but still no luck.
Has anyone encountered the same problem and point me to a potential solution?
Many cheers!
I have developed a plugin which fetches posts from another websites API. I have two post types on my local site: post1 and post2
Plugin compares post1 to post2 and syncs only the missing post2 posts from the API.
So, a new post is generated:
function insert_local_post( $local_post ) { // insert new post
$post_data = array(
'post_type' => 'post2',
'post_status' => 'private',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'post_name' => $local_post->post_name,
'post_title' => $local_post->post_title,
'post_date' => $local_post->post_date,
'post_date_gmt' => $local_post->post_date_gmt,
'post_content' => '',
);
$new_post = wp_insert_post( $post_data );
if ( $new_post ) {
update_field( 'unique_identifier', get_field( $this->local_post_identifier, $local_post->ID ), $new_post );
}
return $new_post;
}
After creating the post, post status gets changed to ‘publish’ and updating the fields is called:
$publish = array( 'ID' => $ID, 'post_status' => 'publish' );
wp_update_post($publish);
$this->update_local_fields( 'fields1', $fields, $ID);
$this->update_local_fields( 'fields2', $fields, $ID);
$this->update_local_fields( 'fields3', $fields, $ID);
For fields I have a field conf file with a hierarchical set of extra field names. Same hierarchical structure as the fields coming from the API.
Function for updating the fields:
function update_local_fields( $field_group_name, $fields, $ID ) {
foreach ( $this->field_conf[$field_group_name] as $field_key => $field_name ) {
if ( ! is_numeric( $field_key ) ) {
$this->delete_local_repeater_fields( $field_key, $ID );
$this->insert_local_repeater_fields( $field_key, $ID, $fields->$field_key, $field_group_name );
continue;
}
if ( $fields->$field_name and
( $field_name == 'taxonomy1' or
$field_name == 'taxonomy2' or
$field_name == 'taxonomy3' ) ) {
$fields->$field_name = $this->link_to_local_taxonomy_terms( $fields->$field_name );
}
update_field( acf_get_field($field_name)['key'], $fields->$field_name, $ID );
}
return;
}
The main chunk of code for creating the rows and subrows for repeater fields:
function insert_local_repeater_fields( $repeater_row_name, $ID, $fields, $field_group_name ) {
$local_repeater_name = $repeater_row_name;
if ( $fields ) {
for ( $i = 0; $i < sizeof($fields); $i++ ) {
$row_data = array();
foreach ( $this->field_conf[$field_group_name][$repeater_row_name] as $row_field ) {
if ( ! is_array($row_field) ) {
$local_row_field = $row_field;
if ( $fields[$i]->$row_field and $row_field == 'location' ) {
$fields[$i]->$row_field = $this->link_to_local_taxonomy_terms( $fields[$i]->$row_field );
}
$row_data[$local_row_field] = $fields[$i]->$row_field;
}
}
add_row(acf_get_field($local_repeater_name)['key'], $row_data, $ID);
if ( $fields[$i]->cities ) {
foreach ( $fields[$i]->cities as $city) {
$sub_row_data = array();
foreach ( $this->field_conf[$field_group_name][$repeater_row_name]['cities'] as $sub_row_field ) {
$local_sub_row_field = $sub_row_field;
if ( $city->$sub_row_field and $sub_row_field == 'game' ) {
$city->$sub_row_field = $this->link_to_local_taxonomy_terms( $city->$sub_row_field );
}
$sub_row_data[$local_sub_row_field] = $city->$sub_row_field;
}
add_sub_row( array(acf_get_field($local_repeater_name)['key'], ($i + 1), 'cities'), $sub_row_data, $ID );
}
}
}
}
}
The problem is that the fields only show up when I manually update the post and run the sync again. I have tried a million things: using keys instead of fields etc, but still no luck.
Has anyone encountered the same problem and point me to a potential solution?
Many cheers!
I wonder why so many threads on this forum are simply ignored literally for years. Every single one I find has 0 answers or responses, it looks like ACF support is quite useless.
This forum is users helping users. There is generally no one involved in the actual development of ACF that monitors these forums and answers questions. The only exception to this it what the developers to a bit of monitoring after a new version is released and then they only look for topics that could be bugs.
Me, I’m just a glorified user of ACF. I use it a lot and I know a lot about it. I do my best to answer questions that I can answer, but I have my limits. I’m also not able to come here all the time and I might miss a few.
The main reason that questions go unanswered for a long time can be complex. There simply may not be anyone that knows the answer. Or the question does not have enough information. Or the question does not really have anything to do with ACF or it does but in combination with some other plugin that no one understands. As an example of the last there are a lot of questions that have to do with using ACF in combination with some page builder and it would be important to understand that page builder to answer the question.
In the case of the OP, I may have missed it a year ago. Or I looked at it and could not really figure out what was going on. Looking at it now there is information that is unclear and quite honestly, I don’t even know what I would ask that would get the OP to supply the information I am lacking.
I can only do so much by myself. There are others that do answer questions, but like me they all have their areas of expertise. This forum can always use more people willing to contribute their time to help others.
The topic ‘ACF repeater fields not showing up before manual update’ 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.