Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Force to change current page post object in WordPrress
// $post = get_post( 33, OBJECT ); // use ID or
$post = get_page_by_path( $path ); // url path such as /people/staff or /people/staff/ both work
setup_postdata( $post ); // change global post object
$post->ID; // new ID
wp_reset_postdata(); // reset to original post data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment