Php 将post meta限制为特定模板

Php 将post meta限制为特定模板,php,wordpress,Php,Wordpress,我试图将post meta限制为特定的模板 这段代码似乎做到了这一点 $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); 但是当运行调试时,我得到了未定义的索引:post_ID/post error 有没有其他选择或者你能帮我解决这个问题 编辑: 用if(isset($\u GET['po

我试图将post meta限制为特定的模板

这段代码似乎做到了这一点

$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
但是当运行调试时,我得到了未定义的索引:post_ID/post error

有没有其他选择或者你能帮我解决这个问题

编辑:


if(isset($\u GET['post'])包装整个代码,这为我修复了它。

未定义索引
并不表示错误。它只是意味着变量
$\u POST['POST\u ID']
不存在。您应添加此选项以隐藏通知:

error_reporting(E_ALL ^ E_NOTICE);

用你的三元组来避免你可能想要的警告

$post_id = isset($_GET['post']) ? $_GET['post'] : $_POST['post_ID'] ;

在尝试执行此操作之前,它将检查值post是否存在于
$\u GET['post']
,同时不会发出警告。

是,修复了未定义的索引:post\u ID/post问题,但现在$post\u ID未定义。请注意,标记是独立的。不能组合多个标记来创建新概念。也就是说,组合
post
meta
并不意味着你在谈论Wordpress
get\u post\u meta
函数。