Skip to content

Commit

Permalink
Merge pull request #106 from newfold-labs/fix/use-path-from-sitemap-data
Browse files Browse the repository at this point in the history
Fix Path Issue in Extra Pages
  • Loading branch information
arunshenoy99 authored Jul 31, 2024
2 parents 2e998cb + 23a84bf commit 73365be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,22 @@ public static function publish_sitemap_pages( $site_description, $content_style,
continue;
}

$slug = '';
if ( isset( $page['path'] ) ) {
$slug_paths = explode( '/', $page['path'] );
if ( count( $slug_paths ) > 1 ) {
$slug = $slug_paths[1];
}
}
$page_content = $other_pages[ $page['slug'] ];
$post_id = SitePagesService::publish_page(
$page['title'],
$page_content,
true,
array(
'nf_dc_page' => $page['slug'],
)
),
$slug
);

if ( $update_nav_menu && ! is_wp_error( $post_id ) ) {
Expand Down
7 changes: 6 additions & 1 deletion includes/Services/SitePagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class SitePagesService {
* @param string $content The content(block grammar/text) that will be displayed on the page.
* @param boolean $is_template_no_title checks for title
* @param boolean|array $meta The page post_meta.
* @param string $slug The page slug that will be used in the page url.
* @return int|\WP_Error
*/
public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false ) {
public static function publish_page( $title, $content, $is_template_no_title = false, $meta = false, $slug = null ) {
$post = array(
'post_title' => $title,
'post_status' => 'publish',
Expand All @@ -31,6 +32,10 @@ public static function publish_page( $title, $content, $is_template_no_title = f
$post['page_template'] = 'no-title';
}

if ( $slug && '' != $slug ) {
$post['post_name'] = $slug;
}

return \wp_insert_post( $post );
}

Expand Down

0 comments on commit 73365be

Please sign in to comment.