hooks – How to load another post if condition is true

Question

if a condition is true I want to display another post selected by its id on single.php.
I have this, that gives me the current id. But how can I load the content (title and acf-fields) of another post. I tried “the_content” but it did not work.

function change_post() {
 $post = get_post();
 echo $post->ID;
 //lets say we have id 1
 if($conditon){     
   echo "load post 2" 
 }
}
add_filter( 'wp', 'change_post' );

0
buckdanny 1 month 2021-12-15T15:47:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse