Custom wordpress post content by examples

WordPress usually display post content by the_content() or get_the_content() function, these content is edited by wordpress editor, so wordpress display what you have written.
Consider one situation, you want to display similar posts in single page, and you add post id, for example: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.


1.Custom post content by add_filter

function get_similar_posts($content){

if ( is_single() ){

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

// query and save content in $content

return $content;




Leave a Reply

Your email address will not be published. Required fields are marked *