Skip to content

Instantly share code, notes, and snippets.

@Danushka181
Created June 22, 2020 12:20
Show Gist options
  • Save Danushka181/0f4b7be70c1d3e63e8f6d89f3da667bb to your computer and use it in GitHub Desktop.
Save Danushka181/0f4b7be70c1d3e63e8f6d89f3da667bb to your computer and use it in GitHub Desktop.
Make pages dynamicaly as loop
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