Created
April 7, 2020 07:09
-
-
Save simongcc/b29cb38ce243e9d4931b86084ddf011e to your computer and use it in GitHub Desktop.
Force to change current page post object in WordPrress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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