如何将结构化数据 mainEntity 添加为数组 @type 问题?
正如您从我的代码中看到的,我需要将主要实体作为一个数组,以便我可以将高级自定义字段转发器行传递到架构中以尝试构建FAQ。
我试图传递到结构化数据中的字段是一个非常基本的 ACF 转发器,您可以在这里看到:
<section class="faq">
<div class="container max-width px-5">
<div class="row">
<div class="col-lg-6 features-title-block">
<h2 class="mpc-header"> <?php if ( get_field('faq_header') ) : ?>
<?php the_field('faq_header'); ?>
<?php endif; ?></h2>
<?php if ( get_field('faq_sub_text') ) : ?>
<div class="pb-5"><?php the_field('faq_sub_text'); ?></div>
<?php endif; ?>
</div>
<div class="col-lg-6">
<?php if ( have_rows('faq') ) : ?>
<div class="accordion" id="accordionExample">
<?php while( have_rows('faq') ) : the_row(); ?>
<div class="card">
<div class="card-header" id="heading<?php echo get_row_index(); ?>">
<h2 …Run Code Online (Sandbox Code Playgroud) 在 Woocommerce 中,我尝试向我的产品添加一段自定义元,我想将其传递给订单。
我们有大量的产品,它们负责不同的成本中心,所以我需要产品管理中的一个选择框,我们可以选择将值传递到订单中的成本中心,这不需要由客户查看,但管理员需要在订单中以及每月的订单导出中查看以进行会计处理。
这是我到目前为止所拥有的,这将在产品编辑页面(管理员)中显示选择框:
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
woocommerce_wp_select(
array(
'id' => '_select',
'label' => __( 'Cost Centre', 'woocommerce' ),
'options' => array(
'one' => __( 'MFEG', 'woocommerce' ),
'two' => __( 'YDIT', 'woocommerce' ),
)
)
);
echo '</div>';
}
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields_save( $post_id ){
// Select
$woocommerce_select = $_POST['_select'];
if( !empty( $woocommerce_select ) )
update_post_meta( $post_id, '_select', …Run Code Online (Sandbox Code Playgroud) 我通过在本地运行引导程序来使用它,但它不起作用。但是当我使用 CDN 链接时,它可以工作。谁能帮我解决这个问题吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="bootstrap.min.css" type="text/css">
<script src="bootstrap.min.js"> </script>
</head>
<body>
<form class="row g-3">
<div class="col-md-6">
<label for="inputEmail4" class="form-label">Email</label>
<input type="email" class="form-control" id="inputEmail4">
</div>
<div class="col-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck">
<label class="form-check-label" for="gridCheck">
Check me out
</label>
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
注意:〜 bootsrap.min.css 和 bootstrap.min.js 文件位于我运行该项目的文件夹本身中。