0

I'm adding some pages pragmatically as a subpage. This all works well on a test website in 1 locale. However, on the live website we have WPML with 2 locales. When adding them there, these pages DO NOT show up in the all pages list.

Also accessing their url give a 404. However, when you access the edit mode directly: https://xxxxxxx.nl/wp-admin/post.php?post=3280&action=edit&lang=nl The page 'comes to life' (even without saving) and is visible as sub-page in the 'all pages' page.

Any idea how to get this working properly upon insertion in the db by PHP? Thanks!

function add_my_custom_page() {

    for( $i=1; $i <= 3; $i++ ) {

        $my_posts = array(
          'post_title'    => wp_strip_all_tags( "Video $i" ),
          'post_name'     => "v-$i",
          'post_type'     => "page",
          'post_content'  => 'test',
          'post_status'   => "publish",
          //'post_excerpt'  => "v-$i",
          'post_parent'   => 3269,

          'post_author'   => get_current_user_id(),
          'page_template' => "page-full-width.php",
        );

    

        // Insert the post into the database
        wp_insert_post( $my_posts, true );
        
    }

}
2
  • This is probably related to WPML, you need to ask this in a WPML community or reproduce the problem without WPML so it's confirmed the plugin is unrelated. 3rd party plugin user/dev support questions are offtopic here
    – Tom J Nowell
    Commented May 19, 2022 at 15:00
  • just a wild guess here, but maybe set the language before inserting via do_action('wpml_switch_language', 'es'); where 'es' is the language you want to system to operate in..?
    – honk31
    Commented May 20, 2022 at 14:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.