Skip to content

Block Bindings: get_post_meta() returns null for custom taxonomy field with correctly saved value #66509

@valentin-grenier

Description

@valentin-grenier

Description

When retrieving a custom taxonomy field value using get_post_meta() for a taxonomy (e.g. member_type), the function unexpectedly returns NULL, despite the field being populated with valid data in the database. However, dumping the raw data from get_post_meta() shows that the information is stored correctly in the database.

Step-by-step reproduction instructions

  1. Create and configure the taxonomy field (e.g member_type) and attach the taxonomy field to a post type and save a term value.
  2. Include this code snippet into your functions.php file:
add_action('init', 'themeslug_register_block_bindings');
function themeslug_register_block_bindings()
{
    register_block_bindings_source(
        'themeslug/member-type',
        array(
            'label' => __("Member type", "themeslug"),
            'get_value_callback' => 'themeslug_callback_meta_type'
        )
    );
}
function themeslug_callback_meta_type()
{
    $member_type = get_post_meta(get_the_ID(), 'member_type', true);
    return $member_type;
}
  1. Bind a paragraph block:
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"themeslug/member-type"}}}} -->
<p>Meta type</p>
<!-- /wp:paragraph -->
  1. Attemp data retrieval using get_post_meta(get_the_ID(), 'member_type', true) to retrieve the term ID associated with the post.
  2. get_post_meta() returns NULL

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress version: 6.6.2
  • Gutenberg not installed

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block bindings[Status] Needs More InfoFollow-up required in order to be actionable.[Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions