I have an about page in wordpress, I wanted its content to appear in the home page, I managed to do that using this code that I found through searching
<?php
$my_id = 256;
$post_id_256 = get_post($my_id);
$content = $post_id_256->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
开发者_开发知识库
That works perfect. Now the page also has a costume field with I nee to also get - I tried to manipulate the above code (specially lines 2 and 3) but I cant get the costume field
Hope you can help
Thanks
You can get custom fileds with get_post_meta(), like so:
<?php
$custom_field = get_post_meta(256, 'name_of_your_custom_field');
echo $custom_field;
?>
Use below function to get the post's custom field values:
$meta_values = get_post_meta($post_id, $key);
精彩评论