admin管理员组文章数量:1323029
i added following code to use custom template for my recipes single page
function override_single_template( $single_template ){
global $post;
if ($post->post_type == "recipes"){
$single_template = plugins_url('/recipe-single-page-template.php',__FILE__);
}
return $single_template;
}
add_filter( 'single_template', 'override_single_template',10);
and in my template i added following code
<?php
/*
Template Name: recipe-single-page-template
Template Post Type: recipes
*/
require_once("../../../wp-load.php");
?>
<?php get_header(); ?>
<?php echo $post->ID?>
<?php get_footer(); ?>
but i do not access the post and echo out post id will cuses the following error
Trying to get property of non-object
var dump $post outputs null
NULL
and following code will print out my custom template address
$current_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $current_url;
top code result:
/wp-content/plugins/recipe-plugin/templates/single-recipes.php
now whate should i do?
本文标签: phpi can not access the post in custom template of my wordpress plugin
版权声明:本文标题:php - i can not access the post in custom template of my wordpress plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742110658a2421239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论