wordpress get excerpt by id

I’m using the options framework

and i can’t work out why this doesnt work

Read More
$x = of_get_option('post_number');
$content_post = get_post($x);
echo $content_post->post_excerpt;

its very odd because

echo of_get_option('post_number');

works perfectly and outputs a number

and according to get_post my code should work
yet the echo produces nothing, not even an error message

so i must be handeling get_post() incorrectly somehow, any clues?


EDIT

var dump http://pastebin.com/ZEgQ5WPn
reveals that post_content is full but post_excerpt is empty

how do i regenerate the excerpt?


EDIT [resolved]

i decided to manualy overwrite the excerpt but my option was missing, then i found this

and used

add_post_type_support( 'page', 'excerpt' );

to manualy write the excerpt

Related posts

Leave a Reply

3 comments

  1. This will take the post_content and create an excerpt out of it. You can substitute the post_content for any other string of code. Change the 55 to another number to increase the amount of words returned.

    $excerpt = wp_trim_words ( strip_shortcodes( $recent["post_content"], 55 ) );
    
  2. You should be able to use get_post() like this, which returns almost all built-in post attributes as part of the post object.

    <?php
      $my_id = 7;
      $my_post = get_post( $my_id ); 
      $my_excerpt = $my_post->post_excerpt;
      var_dump( $my_excerpt );
    ?> 
    

    If that fails (it shouldn’t, but perhaps you’ve tried by the sound of it) maybe checkout out WP_Query and pass in "p=$my_id" as a param. This is likely the function used under the get_post hood anyways.

    <?php
      $my_id = 7;
      $my_posts = new WP_Query( "p=$my_id" ); 
      var_dump( $my_posts );
    ?>