Wordpress get excerpt by id

I use parameter frames

and I can’t understand why this is not working

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

very strange because

 echo of_get_option('post_number'); 

works fine and prints a number

and according to get_post my code should work but the echo doesn’t give anything, even an error message

so I have to handle get_post () incorrectly, any hints?


EDIT

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

How can I restore exposure?


EDIT [allowed]

I decided to manually overwrite the excerpt, but my option was missing, then I found this

and used

 add_post_type_support( 'page', 'excerpt' ); 

for manual recording of shutter speed

+6
source share
3 answers
 $text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id)); 
+25
source

This will take post_content and create an excerpt from it. You can replace post_content with any other line of code. Change 55 to another number to increase the number of words returned.

 $excerpt = wp_trim_words ( strip_shortcodes( $recent["post_content"], 55 ) ); 
+2
source

You can use get_post () , which returns almost all of the built-in message 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 this does not work (it is not, but you may have tried its sound), maybe exit WP_Query and go to "p=$my_id" as a parameter. This is probably the function used under the get_post hood.

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

Source: https://habr.com/ru/post/919912/


All Articles