[wp-trac] [WordPress Trac] #25191: Regarding Access of excerpt of Page
WordPress Trac
noreply at wordpress.org
Mon Sep 2 08:54:04 UTC 2013
#25191: Regarding Access of excerpt of Page
-------------------------------+------------------------------
Reporter: alpesh1988 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback |
-------------------------------+------------------------------
Comment (by SergeyBiryukov):
Pages indeed don't have an Excerpt meta box by default, but you can add it
using [http://codex.wordpress.org/Function_Reference/add_post_type_support
add_post_type_support()] in theme's `functions.php` file::
{{{
function my_custom_init() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'my_custom_init' );
}}}
This would only work if the page has the `post_excerpt` database field
actually filled in via the meta box.
{{{
$page_id = 2; // Sample Page
$post = get_post( $page_id );
echo $post->post_excerpt;
}}}
This, however, works even if `post_excerpt` field is empty, by applying
[http://codex.wordpress.org/Function_Reference/wp_trim_excerpt
wp_trim_excerpt()] function to the content:
{{{
$page_id = 2; // Sample Page
$post = get_post( $page_id );
setup_postdata( $post );
the_excerpt();
wp_reset_postdata();
}}}
This behaviour is the same for posts and pages, it did not change in 3.6
and has nothing to do with `get_page()` soft deprecation in 3.5. This
sounds like a support issue, I don't see a bug here.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25191#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list