get_post_type()函数不返回任何内容

时间:2016-02-12 10:06:55

标签: wordpress

我想要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()工作吗?

2 个答案:

答案 0 :(得分:0)

试试这个(需要在循环内)

global $post;
get_post_type($post->ID)

圈外:

<plugin>      
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/src/main/webapp/lib</outputDirectory>
                <includeScope>compile</includeScope>
            </configuration>
        </execution>
    </executions>
</plugin> 

答案 1 :(得分:0)

您是否想在循环中完成此操作?如果是这样,你可以尝试:

$current_post_type = get_post_type( $post->ID );
echo $current_post_type;
相关问题