تخطي الملاحة
Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

المنطقة الزمنية الداعمة: America/Los_Angeles (GMT-08:00)

الوسوم: 

يحتوي هذا الموضوع رد واحد ، لديه 1صوت.

آخر تحديث بواسطة nickD-21 قبل 10 أشهر، 3 أسابيع.

يساعده: Bobby.

مؤلف المقالات
مارس 13, 2024في 9:46 م #15406026

nickD-21

How can i create a new post in de default language (english = en) with wpml.
If i use en as languagecode i see a new post on all the languages of wpml.

// Create an array of post details for the new post
$new_post = array(
'post_title' => $titelx, // Parsed post data - Set the title ofthe new post
'post_content' => $inhoudx, // Post content - Set the content ofthe new post
'post_type' => 'post', // Processed post data - Set the posttype to 'post'
'post_status' => 'publish', // Post status - Set the status ofthe new post to 'publish'
'post_author' => 1, // Replace with the desired author's user ID
'post_date' => $datumx, // Post date - Set a custom post date and time
// 'tags_input' => array('tag1', 'tag2', 'tag3'), // Processedttachment post data - Set tags for the new post
// 'page_template' => 'custom-template.php', // Invalid pagetemplate - Set a custom page template for the post
);

// Insert WordPress post into the database
$post_id = wp_insert_post($new_post); // Existing attachment post -Set the existing post ID for updating

// Check if the post was successfully inserted
if (!is_wp_error($post_id)) {
// The post was successfully inserted, and $post_id contains the post ID

// Get the post meta field based on the post ID
$meta_value = get_post_meta($post_id, 'meta_key_name', true);

// Add custom post categories (replace with actual category IDs)
$post_categories = $catid; // Filters attachment post data -Category IDs to assign to the post
wp_set_post_categories($post_id, $post_categories); // Set post categories

// Add custom post meta data
update_post_meta($post_id, '_custom_meta_key', $titelx); // Replace'_custom_meta_key' with your custom meta key and set its value

// Get the post type
$type = get_post_type($post_id);

// Get the translation id (trid)
$trid = wpml_get_content_trid('post_' . $type, $post_id);

// Set the desired language
$language_code = $taalcodex;

// Update the post language info

$language_args = ['element_id' => $post_id, 'element_type' => 'post_' . $type,
'trid' => $trid, 'language_code' => $language_code, 'source_language_code' => null, ];

do_action('wpml_set_element_language_details', $language_args);

الموضوع '[مغلق] Create a post in the default language ' مغلق أمام الردود الجديدة.