Reputation: 195
I have created a custom meta box which displays only on the home page when I go in to edit the page.
This is all working great, but I want to carry the text entered on the home page custom meta box on every page.
I currently have the following code that outputs the text:
<?php echo get_post_meta(get_the_ID(), 'my_meta_box_text_challengetbl', true); ?>
The question is how do I get the custom meta box text entered on the home page for every page?
Upvotes: 0
Views: 134
Reputation: 2401
<?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.
Upvotes: 1
Reputation: 27092
Assuming you have a static front page, you can get the ID of the front page by using get_option()
, and then retrieve the post meta using that ID:
$front_page_ID = get_option('page_on_front');
echo get_post_meta($front_page_ID, 'my_meta_box_text_challengetbl', true);
Read more about options in the Codex.
Upvotes: 0