WP后元数据在后端示出但不前端/相同的代码
问题描述:
情况:使用PHP文件(table_template.php)与include_once表明元数据WP后元数据在后端示出但不前端/相同的代码
。在后端(在metabox内)使用这个模板显示所有内容 - 在前端(内部)使用相同的模板,表格元数据不显示(但来自自定义字段的其他元数据)。
变种转储在后端:
串(65) “[[” 测试值1" , “测试值2”, “测试值3”],[ “测试值”,”试验值b “ ”测试值c“]]” 的前端
变种转储:
串(6) “[[”, “]]”
代码从table_template .php:
<?php
/* TEMPLATE TO RENDER THE TABLE (AS PREVIEW) IN THE BACKEND AND FRONTEND */
global $post;
$table_meta = get_post_meta($post->ID, 'psg_table_meta', true) ?
get_post_meta($post->ID, 'psg_table_meta', true) : '[[""]]';
$t = json_decode($table_meta);
$c_id = get_post_meta($post->ID);
$c = get_post($c_id);
?>
<div class="psg_box_table">
<table class="psg_table ">
<thead>
<tr>
<?php foreach ($t[ 0 ] as $col): ?>
<th>
<?php echo $col; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($t as $idx => $row): ?>
<?php if ($idx == 0)
continue; ?>
<tr>
<?php foreach ($row as $col): ?>
<td>
<div class="psg_table_content">
<?php echo str_replace('"', '"', $col) ?>
</div>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!--END SIZING CHART TABLE -->
我如何加载模板:
include_once("table_template.php");
答
的问题是,我不应该检查该帖子ID(该表的元数据不直接在后,但在它的选定/链接的帖子。所以我不得不更换
$table_meta = get_post_meta($post->ID, 'psg_table_meta', true) ?
与
$table_meta = get_post_meta($psg_selected, 'psg_table_meta', true) ?
答
如果您正在使用内部的WP_Query
循环的模板,然后更换
$post->ID
与
get_the_ID();
另请检查psg_table_meta
键是否正确。
+0
谢谢艾哈迈德。虽然这不是完全正确的答案,但是您会引导我走向正确的道路,我想为此感谢您,并接受您的答案是正确的。 – GTO
的问题是,我不应该检查该帖子ID(该表的元数据不直接在后,但在它的选定/链接的帖子。所以我不得不更换$ table_meta = get_post_meta ($ post-> ID,'psg_table_meta',true)?with $ table_meta = get_post_meta($ psg_selected,'psg_table_meta',true)? – GTO