繁体   English   中英

WordPress非法字符串偏移错误

[英]WordPress Illegal string offset error

我有一个为WordPress网站构建的自定义帖子类型。 除了我添加新帖子时,所有功能均应正常运行,自定义元字段充满错误。

<br /><b>Warning</b>:  Illegal string offset 'Title' in <b>D:\Xampp\htdocs\wpexercise\wordpress\wp-content\themes\wpexercise\functions.php</b> on line <b>69</b><br />

我可以从输入字段和输入数据中删除错误,并将其保存,但是为什么会出现此错误。 请帮忙。

functions.php

function create_post_products_post() {
register_post_type( 'products_post',
    array(
        'labels'       => array(
            'name'       => __( 'Products' ),
        ),
        'public'       => true,
        'hierarchical' => true,
        'has_archive'  => true,
        'supports'     => array(
            'title',
            'editor',
            'excerpt',
            'thumbnail',
        ),
        'taxonomies'   => array(
            'post_tag',
            'category',
        )
    )
);
register_taxonomy_for_object_type( 'category', 'products_post' );
register_taxonomy_for_object_type( 'post_tag', 'products_post' );
}
add_action( 'init', 'create_post_products_post' );



function add_products_fields_meta_box() {
add_meta_box(
    'products_fields_meta_box', // $id
    'Product Fields', // $title
    'show_products_fields_meta_box', // $callback
    'products_post', // $screen
    'normal', // $context
    'high' // $priority
);
}
add_action( 'add_meta_boxes', 'add_products_fields_meta_box' );

function show_products_fields_meta_box() {
global $post;
$meta = get_post_meta( $post->ID, $key='products_fields', true ); ?>

<input type="hidden" name="products_meta_box_nonce" value="<?php echo 
wp_create_nonce( basename(__FILE__) ); ?>">

<p>
    <label for="products_fields[Title]">Product Title</label>
    <br>
    <input type="text" name="products_fields[Title]" 
id="products_fields[textTitle]" class="regular-text" value="<?php echo 
$meta['Title']; ?>">
</p>

<p>
    <label for="products_fields[Link]">Product Link</label>
    <br>
    <input type="text" name="products_fields[Link]" id="products_fields[Link]" class="regular-text" value="<?php echo $meta['Link']; ?>">
</p>

<p>
    <label for="products_fields[bkgColor]">Background Color</label>
    <br>
    <input type="text" name="products_fields[bkgColor]" 
id="products_fields[bkgColor]" class="regular-text" value="<?php echo 
$meta['bkgColor']; ?>">
</p>

<p>
    <label for="products_fields[Image]">Product Image Path</label>
    <br>
    <input type="text" name="products_fields[Image]" 
id="products_fields[Image]" class="regular-text" value="<?php echo 
$meta['Image']; ?>">
</p>

感谢开庆,这是对我有用的回应

<?php echo isset($meta['Title']) ? $meta['Title'] : ''; ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM