最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Define global custom post

programmeradmin0浏览0评论

I have create a custom post object with custom post metas.

Like this:

$post->custom_meta = get_post_meta();

$custom_post = $post;

Am I how to define the $custom_post object to global in master level?

Can I request any file it like single.php

global $custom_post;

the_title();

echo $custom_post->custom_meta;

or index.php

global $custom_post;

// The Loop
if ( $custom_post->have_posts() ) {
    echo '<ul>';
    while ( $custom_post->have_posts() ) {
        $custom_post->the_post();
        echo '<li>' . get_the_title() . '</li>';
        echo $custom_post->custom_meta;
    }
    echo '</ul>';
} else {
    // no posts found
}

How to set $custom_post an global and in where? (functions.php?) thx.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论