Created
October 1, 2021 07:14
-
-
Save michaelbragg/e2ee6844bc4bf93013238bd4a496e23e to your computer and use it in GitHub Desktop.
[WordPress] Themes: Populate the 'Posts Page' with content from the Editor.
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 | |
/** | |
* Pull content from Posts Page into home template. | |
* | |
* @param WP_Query $query WP Query. | |
* | |
* @return WP_Query | |
*/ | |
function ti_load_home_content( $query ) { | |
// Discard if not the main query. | |
if ( ! $query->is_main_query() ) { | |
return; | |
} | |
// Stop if this is inside the WP Admin area. | |
if ( is_admin() ) { | |
return; | |
} | |
// Stop if we are not on the home (post archive) page. | |
if ( ! is_home() ) { | |
return; | |
} | |
$query->set( 'post_type', 'page' ); | |
$query->set( 'p', get_option( 'page_for_posts' ) ); | |
return $query; | |
} | |
add_action( | |
'pre_get_posts', | |
'ti_load_home_content' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment