Created
June 22, 2020 12:20
-
-
Save Danushka181/0f4b7be70c1d3e63e8f6d89f3da667bb to your computer and use it in GitHub Desktop.
Make pages dynamicaly as loop
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
function makePages(){ | |
$pages_list = array( | |
'Hotels', | |
'Offers', | |
'Gallery', | |
'Social Wall', | |
); | |
// Create post object | |
for ($i = 0; $i < count( $pages_list ) ; $i++) { | |
if( ! get_page_by_title($pages_list[$i]) ){ | |
wp_insert_post( | |
array( | |
'post_type' => 'page', | |
'post_title' => $pages_list[$i], | |
'post_content' => '', | |
'post_status' => 'publish', | |
'post_author' => 1, | |
) | |
); | |
} | |
} | |
} | |
add_action( 'init', 'makePages', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment