我创建了一个自定义元框,当我进入编辑页面时,它只显示在主页上 .
这一切都很好,但我想在每个页面上携带在主页自定义元框中输入的文本 .
我目前有以下代码输出文本:
<?php echo get_post_meta(get_the_ID(), 'my_meta_box_text_challengetbl', true); ?>
问题是如何获取每个页面在主页上输入的自定义元框文本?
<?php $homePageId = get_option('page_on_front'); echo get_post_meta($homePageId, 'my_meta_box_text_challengetbl', true); ?>
Here's a list of many useful get_option parameters.
假设您有一个静态首页,您可以使用 get_option() 获取首页的ID,然后使用该ID检索post元:
get_option()
$front_page_ID = get_option('page_on_front'); echo get_post_meta($front_page_ID, 'my_meta_box_text_challengetbl', true);
阅读有关选项的更多信息in the Codex .
2 回答
Here's a list of many useful get_option parameters.
假设您有一个静态首页,您可以使用
get_option()
获取首页的ID,然后使用该ID检索post元:阅读有关选项的更多信息in the Codex .