get_post_type()函数不返回任何东西
问题描述:
我想要get_post_type
当前帖子。get_post_type()函数不返回任何东西
如果我尝试get_post_type()
,它不会返回任何东西。
我试过get_post_type(124)
它工作。 124是当前的post_id。
在我的孩子主题function.php
<?php
global $post;
$my_post_type = get_post_type($post->ID);
?>
可有人告诉我如何使get_post_type()
工作?
答
试试这个(必须是内环路)
get_post_type(get_the_ID())
外循环:
global $post;
get_post_type($post->ID)
答
你们是不是要在一个循环中做到这一点?如果是这样,你可以尝试:
$current_post_type = get_post_type($post->ID);
echo $current_post_type;
+0
我不要放在循环中,我只是把它们放在child.php中。 – John
我不放在循环内。我只是把它们放在了儿童主题的function.php中。 – John
第二个选项应该适合你 – designtocode
我得到了错误:注意:试图获取非对象的属性在C:\ xampp \ htdocs \ wp-content \ themes \ ma-child \ functions.php 92行 – John