admin管理员组文章数量:1122832
I need to copy the Value from one Meta to another Meta.
Meta_key1 --> "Custom value1" (This value is inserted by the ERP) Meta_key2 --> "Custom value1" (I want it to copy the value of Meta_key1)
First, as you see in the image below. In my store there is a Custom Meta that collects the Ean Code of the Product. This code is sent by the ERP. META = EAN, KEY = BARCODE
Second. What I want is that the meta indicated in the picture, collects the same value as the EAN meta above.
@
I need to copy the Value from one Meta to another Meta.
Meta_key1 --> "Custom value1" (This value is inserted by the ERP) Meta_key2 --> "Custom value1" (I want it to copy the value of Meta_key1)
First, as you see in the image below. In my store there is a Custom Meta that collects the Ean Code of the Product. This code is sent by the ERP. META = EAN, KEY = BARCODE
Second. What I want is that the meta indicated in the picture, collects the same value as the EAN meta above.
@
Share Improve this question edited Apr 23, 2024 at 14:11 Pat J 12.3k2 gold badges28 silver badges36 bronze badges asked Apr 22, 2024 at 13:03 Amelia JCAmelia JC 11 bronze badge 1- 1 your question is not clear, can you please provide more details. – msz Commented Apr 22, 2024 at 14:54
1 Answer
Reset to default 0If you just need get_post_meta( $post_id, 'ywbc_barcode_display_value_custom_field', $single );
to return the value that's stored in ean
, you can filter the get_post_meta()
call to return that value:
add_filter( 'get_post_metadata', 'wpse424858_filter_meta_value', 10, 4 );
/**
* Filters the barcode display meta value.
*
* @param mixed $value The existing meta value.
* @param int $id The post ID.
* @param string $key The meta key. We're looking for 'ywbc_barcode_display_value_custom_field'.
* @param bool $single Return a single value or an array?
*/
function wpse424858_filter_meta_value( $value, $id, $key, $single ) {
if ( 'ywbc_barcode_display_value_custom_field' === $key ) {
// Gets the value stored in the 'ean' meta.
return get_post_meta( $id, 'ean', $single );
}
// Otherwise, returns what we were provided.
return $value;
}
Note: This code is untested and is meant as a starting point rather than a finished product. Try it out on a test site before putting it into production.
Doing it this way means that there's not a duplication of data in your DB.
References
get_{$meta_type}_metadata
filter (the{$meta_type}
in this case ispost
)
本文标签: copy the Value from one Meta to another Meta
版权声明:本文标题:copy the Value from one Meta to another Meta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309480a1934037.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论