Skip to content

Instantly share code, notes, and snippets.

@simongcc
Created April 7, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simongcc/b29cb38ce243e9d4931b86084ddf011e to your computer and use it in GitHub Desktop.
Save simongcc/b29cb38ce243e9d4931b86084ddf011e to your computer and use it in GitHub Desktop.
Force to change current page post object in WordPrress
<?php
// $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