Currently I am trying to replace the $post global with another dynamically loaded post in the wp action. However, while even in the templates the correct post data shows when outputting $post, the actual output content isn't updated. I backtraced through the entire the_content function, but I can't find anything out of the ordinary.

Is this even possible, and if so, what am I missing?

  • Changing the $post global is not going to help you as anything later on can change the its value. Even the main loop changes the $post global. IMHO, you are on the wrong track here – Pieter Goosen Feb 26 '16 at 8:39
  • But I assume WordPress is basing these changes to the value on something, isn't it? – Thierry Feb 26 '16 at 9:07
  • $post by default, if nothing breaks it, holds the first post in the loop of the main query – Pieter Goosen Feb 26 '16 at 9:11

You can try with using pre_get_posts


function alter_query($query) { //gets the global query var object global $wp_query;

//gets the front page id set in options
$front_page_id = get_option('page_on_front');

if ( 'page' != get_option('show_on_front') || $front_page_id != $wp_query->query_vars['page_id'] )

if ( !$query->is_main_query() )

$query-> set('post_type' ,'page');
$query-> set('post__in' ,array( $front_page_id , [YOUR SECOND PAGE ID]  ));
$query-> set('orderby' ,'post__in');
$query-> set('p' , null);
$query-> set( 'page_id' ,null);

//we remove the actions hooked on the '__after_loop' (post navigation)
remove_all_actions ( '__after_loop');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.