php 带有附件ID的布局构建器中的facetwp自定义字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 带有附件ID的布局构建器中的facetwp自定义字段相关的知识,希望对你有一定的参考价值。

<?php
/** for using a custom field that saves an image as attachment_id instead of url or path
 ** in the layout builder select the field and give it a unique in the advanced tab https://d.pr/i/xpD9p3
 **/

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
	if ( 'my-image' == $item['settings']['name'] && !empty( $value ) ) { // change my-image to the unique name of your field
		$value = wp_get_attachment_image( $value, 'full' ); // 'full' can be changed to other image sizes you have available
	}
	return $value;
}, 10, 2 );

/** you can also use the source which is generally the custom field name if you know it
 ** but some custom field plugins create names which may be harder to find
 **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
	if ( 'my_custom_image_field' == $item['source'] && !empty( $value ) ) { // change 'my_custom_image_field' to the unique name of your field
		$value = wp_get_attachment_image( $value, 'full' ); // 'full' can be changed to other image sizes you have available
	}
	return $value;
}, 10, 2 );

以上是关于php 带有附件ID的布局构建器中的facetwp自定义字段的主要内容,如果未能解决你的问题,请参考以下文章

php 布局构建器中的facetwp短代码

php 布局构建器中的facetwp数组处理

php facetwp更改布局构建器中的日期格式

php facetwp链接布局构建器中的所有内容

php facetwp自定义图像在布局构建器中提供图像大小

php facetwp woocommerce布局构建器