How to customize wordpress post content to display

WordPress usually display post content by the_content() or get_the_content() function, the content is edited by wordpress editor, so wordpress displays what you have written. However, this way can not meet every situation.

For example, you want to display similar posts in single page, and you add the similar post ids are 1,2,3 by wordpress editor, if you do nothing, wordpress will display:1, 2, 3.If you want to display posts that id is 1,2,3, you can do by add_filter() function.

How to show customized wordpress content?

We use the add_filter() function to do .

function get_similar_posts($content){

if ( is_single() ){

$post_ids = .....// get post id from $content

// query and save content in $content

return $content;

}

}

add_filter("the_content",get_similar_posts);