davidwebca/acf-block-save-to-meta 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

davidwebca/acf-block-save-to-meta

最新稳定版本:0.2

Composer 安装命令:

composer require davidwebca/acf-block-save-to-meta

包简介

Adds a setting to ACF fields to allow saving the data to post meta.

README 文档

README

Since ACF 6.3 released on May 22nd 2024, it is now possible to save a block's meta with a core flag in block.json. Please update to a new version and use that instead. This repo will gladly never get touched again.

ACF Block Save To Meta [WIP]

Allows adding a setting to ACF fields to save the field's data to wp_postmeta. This is a work in progress, use at your own risk.

WARNING

The official ACF team has mentionned that they would add this in core relatively soon. You can follow the related issue here.

Requirements

Installation

Install via Composer:

$ composer require davidwebca/acf-block-save-to-meta

If your theme already uses composer, the filters will be automatically added thanks to the auto-loading and auto-instantiating class. Otherwise, if you're looking for a standalone solution, copy src/ACF_SaveToMeta.php to your theme's folder and include it in functions.php.

Instructions

Every field you need to have saved to post meta needs to have its option checked to "yes" in the field's settings. Fields that don't have this option checked will be ignored and saved normally to the block's meta block in the post content.

Known issues

Currently, this code doesn't check if multiple of the same block or if multiple fields have the same name. If multiple blocks have the option "Save to meta" enabled, or if multiple of these blocks have identical field names, the latest one added to the editor will be the prevalent data, thus the one that will be saved to meta.

A future solution might be added to never allow saving to meta when "multiple" isn't true, but it is currently impractical or impossible to implement.

Also, you'll have to use the regular "get_post_meta()" outside of the post's single (in loops etc.) to get the data because ACF currently looks up field values with "get_field" which passes through some location validation. Since our field is not associated to the post, but to a block on the post, it doesn't always return the right value, especially if you're migrating from a real post (meta) location to a block.

Bug Reports and contributions

All issues can be reported right here on github and I'll take a look at it. Make sure to give as many details as possible since I'm working full-time and will only look at them once in a while. Feel free to add the code yourself with a pull request.

License

This code is provided under the MIT License.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固