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(
            'title' => 'Product registration',
            'template' => 'page-templates/tpl-regprod.php',
            'slug' => 'product-registration'
            'title' => 'Private area',
            'template' => 'page-templates/tpl-private-area.php',
            'slug' => 'private-area'
            '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.

  • 1
    Does it work now? Apr 5, 2019 at 11:02
  • Yes @QaisarFeroz
    – GigiSan
    Apr 5, 2019 at 12:11
  • 1
    Then mark this answer as Accepted Answer so that other people searching for similar issues can find the solution. Apr 5, 2019 at 12:18
  • 1
    I appreciate your diligence @QaisarFeroz, but self-answers can only be accepted after 2 days :) Will surely do so in 2 days
    – GigiSan
    Apr 5, 2019 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.