Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress get_post_meta()从第一个子商业产品页面中提取_Php_Wordpress_Woocommerce - Fatal编程技术网

Php Wordpress get_post_meta()从第一个子商业产品页面中提取

Php Wordpress get_post_meta()从第一个子商业产品页面中提取,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我刚开始使用PHP,现在遇到了一些麻烦 我正在创建一个元框来插入URL,这样我们就可以在我们的WooCommerce主页和产品页面上设置横幅图像 我遇到的问题是,出于某种原因,主商店页面标题从第一个WooCommerce产品页面标题url中提取元数据 functions.php中的代码: add_action( 'add_meta_boxes', 'product_background_url' ); function product_background_url() { $scre

我刚开始使用PHP,现在遇到了一些麻烦

我正在创建一个元框来插入URL,这样我们就可以在我们的WooCommerce主页和产品页面上设置横幅图像

我遇到的问题是,出于某种原因,主商店页面标题从第一个WooCommerce产品页面标题url中提取元数据

functions.php中的代码:

add_action( 'add_meta_boxes', 'product_background_url' );
 
function product_background_url() {
    $screens = get_post_types();
    foreach ($screens as $screen){
        add_meta_box(
        'background',
        'Product Background',
        'product_background_url_mb',
        $screen,
        'side',
        'high'
        );
    }
}

function product_background_url_mb(){
    
    global $post;
    
    ?>
    <label><strong>This field is to only be used for shop product pages!</strong></label><br><label>Insert Banner Image URL Here</label>
    <input type='url' name='product_background' value="<?php echo get_post_meta($post->ID, '_product_background', true) ?>"/>
<?php
}
function product_background_url_mb_save($post_id) {
        update_post_meta( $post_id, '_product_background', $_POST['product_background']);
}
add_action('save_post','product_background_url_mb_save');
add_操作('add_meta_box'、'product_background_url');
函数产品\u背景\u url(){
$screens=get_post_types();
foreach($screens作为$screen){
添加元框(
“背景”,
“产品背景”,
“产品\u背景\u url\u mb”,
$screen,
"一边",,
“高”
);
}
}
函数产品\u背景\u url\u mb(){
全球$员额;
?>
此字段仅用于商店产品页面!
在此处插入横幅图像URL
$backgroundImg = get_post_meta($post->ID, '_product_background', true);

?>


<div class="page-hero"<?php if ( $backgroundImg ) { echo ' style="background-image: url(' . $backgroundImg . ');"'; } ?>>
    <div class="container">
        <div class="title-wrap">
            <h1><?php the_title();?></h1>
            <?php if( $subhead ) { ?>
                <h2><?php echo $subhead; ?></h2>
            <?php } ?>
        </div>
    </div>
</div>