Skip to content

Adding Association field in Theme Options generate an error 500 #1305

@poillic

Description

@poillic

Version

  • Carbon 3.6.9
  • Wordpress 6.8.3
  • PHP 8.3.27

Expected Behaviour

I created an association field in Theme options.

What is expected ?
I can select a max of 4 associated element, save them and modified them later.

Actual Behaviour

When I reload the page after saving post, I'm not able to see and edit the previously picked elements.

Image

Minimum code the generate the issue

<?php

use Carbon_Fields\Container;
use Carbon_Fields\Field;

add_action( 'after_setup_theme', 'crb_load' );
function crb_load() {
    require_once( 'vendor/autoload.php' );
    \Carbon_Fields\Carbon_Fields::boot();
}

function register_courseware_post_type() {
	register_post_type('formation', array(
		'labels' => array(
			'name' => 'Formation',
			'add_new' => 'Ajouter une Formation',
			'add_new_item' => 'Ajouter un nouvelle Formation',
			'singular_name' => 'Formation'
		),
		'public' => true,
		'has_archive' => true, /* True to display all formation in a page */
		'rewrite' => ['slug' => 'formation'],
		'show_in_rest' => true,
		'supports' => array('title'),
		'menu_icon' => 'dashicons-welcome-learn-more'
	));
}
add_action('carbon_fields_register_fields', 'register_courseware_post_type');

add_action('carbon_fields_register_fields', function() {
	Container::make('post_meta', 'Courseware Infos')
		->where('post_type', '=', 'formation')
		->add_fields(array(
			Field::make('image', 'courseware_cover', 'Image de couverture')
				->set_help_text( "Resolution 1350x600 pixels" )
		));
});

/* THEMES OPTIONS */
function crb_attach_theme_options() {
    Container::make( 'theme_options', __( 'Theme Options' ) )
        ->add_fields( array(
			Field::make('association', 'pdfre', 'Formation mise en avant')
				->set_max(3)
				->set_types(array(
					array(
						'type' => 'post',
						'post_type' => 'formation'
					)
				))
        ) );
}
add_action( 'carbon_fields_fields_registered', 'crb_attach_theme_options' );

Step to reproduce

  • Add the code above in functions.php
  • Create one or more "Formation" in backoffice
  • In Theme Options pick one or more "Formation" with the association field
  • Refresh the Theme Options page

Comments

Error URL : http://localhost:8082/wp-json/carbon-fields/v1/association/?container_id=carbon_fields_container_options_du_theme&options=54%3Apost%3Aformation%3B53%3Apost%3Aformation%3B40%3Apost%3Aformation&field_id=pdfre

This may be a loading issue, association field trying to get data from field not yet loaded ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions