Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeater Field values Empty on Frontend (there on backend) After DB Push to Staging #186

Open
matgargano opened this issue Aug 27, 2024 · 1 comment

Comments

@matgargano
Copy link

matgargano commented Aug 27, 2024

Environment:

  • StoutLogic/acf-builder
  • WordPress
  • ACF Pro

Description:
After creating repeater fields locally and pushing the entire database to a staging environment, the fields appear empty on the frontend. However, these fields are visible and populated in the backend. Manually rearranging a repeater field and saving causes the values to display correctly on the frontend. Code example below.

Steps to Reproduce:

  1. Create repeater fields locally using StoutLogic's acf-builder.
  2. Push the local database to a staging environment.
  3. Check the frontend in the staging environment; repeater fields appear empty.
  4. Make a change to the repeater fields in the backend (e.g., rearrange items) and save.
  5. Frontend now displays the repeater fields correctly.

Expected Behavior:
Repeater fields should retain and display their values on the frontend after the database is pushed to staging without requiring any modifications.

Actual Behavior:
Repeater fields are initially empty on the frontend after pushing the database to staging and require a backend modification to display correctly.

Additional Information:

<?php

namespace Kitchen\Blocks;

use StoutLogic\AcfBuilder\FieldsBuilder;


class Kitchen_Image  {

        const BLOCK_SLUG = 'kitchen-image';
	const BLOCK_NAME = 'Kitchen Image';

	public function init(){
		$this->add_fields();
	}


	public function add_fields(){

		add_action('acf/init', function() use($fields){
			if(function_exists('acf_add_local_field_group')) {
				acf_add_local_field_group($fields->build());
			}

		});
	}

	public function register_fields() {
		$section = new FieldsBuilder('section-' . sanitize_title(__FILE__)); // get filename, slugify and lowercase and append it to section
		$section
			->addRepeater('images', ['max' => 5])
			->addImage('image', ['return_format' => 'id'])
			->endRepeater()
			->setLocation('block', '==', 'acf/'  . self::get_name());
		return $section;
	}

	public static function get_name(){
		return sprintf('sw-%s', static::BLOCK_SLUG);
	}



}

in functions.php

$kitchen_image = new \Kitchen\Blocks\Kitchen_Image();
$kitchen_image->init();
@github-staff github-staff deleted a comment from matgargano Aug 27, 2024
@Tanguy-Magnaudet
Copy link

Hello,

I faced that problem long time ago because I was not using WP CLI when migrating the database :

wp search-replace http://localhost:3322 http://www.exemple.com --all-tables

You should also run those command after :

# Fix the action scheduler that may fail after the migration
wp action-scheduler fix-schema
# Flush the cache, just in case
wp cache flush

It most likely will solve yours too as this library doesn't interact with the data it just declare fields in PHP in a more convenient way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@matgargano @Tanguy-Magnaudet and others