Created pages not showing up in ‘All Pages’ list

Due to some custom software integration, I have my theme generate some pages automatically with set templates in order to achieve the required functionalities.

I do so with the following script:
(page names are fictitious but realistic)

function xc_add_custom_pages() {
    // Get pages list, function below
    $pageList = xc_get_custom_page_list();

    foreach ($pageList as $customPage)
    {
        // Check page existence
        if(   !empty($customPage['title']) 
           && !empty($customPage['template']) 
           && !get_page_by_title($customPage['title'])) {
            $pageParams = array(
                'post_type'    => 'page',
                'post_title'    => $customPage['title'],
                'post_content'  => '',
                'post_status'   => 'publish',
                'post_author'   => 1
            ); 
            // Set sutom slug if required
            if ($customPage['slug']) {
                $pageParams['post_name'] = $customPage['slug'];
            }
            // Set sutom template if required
            if ($customPage['template']) {
                $pageParams['page_template'] = $customPage['template'];
            }
            // Create the page
            $customPage['id'] = wp_insert_post( $pageParams );
        }
    }
}
add_action('after_setup_theme', 'xc_add_custom_pages');

function xc_get_custom_page_list() {
    return array(
        array(
            'title' => 'Product registration',
            'template' => 'page-templates/tpl-regprod.php',
            'slug' => 'product-registration'
        ),
        array(
            'title' => 'Private area',
            'template' => 'page-templates/tpl-private-area.php',
            'slug' => 'private-area'
        ),
        array(
            'title' => 'Assistance report',
            'template' => 'page-templates/tpl-asst-report.php',
            'slug' => 'assistance-report'
        ),
        // more pages...
    );
}

Pages have been created yesterday and could be seen in the list until today.
Today I find the total pages count correctly including the custom pages, but no matter what filter I click (‘All’ included) I can only see the ones which were created before my script.

Pages list

I even tried clicking on Tutti (All) and switching to All languages in WPML but I get sent back to the 11 Italian pages. My custom pages do seem to have “no language”, but shouldn’t I see them in All languages then?

Why did the pages “de-list”? Is there a way to list them back?
Thanks in advance for your time. Have a nice day!

1 Answer
1

The problem was actually the pages having “no language” and WPML seems to hate this.

So I just deleted all those pages and re-inserted them with the proper WPML language attributes:

// (...)

// Create the page
$customPage['id'] = wp_insert_post( $pageParams );

// Check if WPML parameters are needed
if (has_action('wpml_set_element_language_details')) {
    // Set WPML parameters
    $set_language_args = array(
        'element_id'    => $customPage['id'],
        'element_type'  => apply_filters( 'wpml_element_type', 'page' ),
        'trid'   => FALSE, // new translation id
        'language_code'   => 'it',
        'source_language_code' => NULL
    );
    do_action( 'wpml_set_element_language_details', $set_language_args );
}

This solved my issue.

Leave a Comment