Home wordpress How to create pages for the desired languages ​​after WP_INSERT_POST ()

How to create pages for the desired languages ​​after WP_INSERT_POST ()

Author

Date

Category

Situation Such …

I add a post via WP_INSERT_POST (). After adding a post, I get the post ID. It is necessary that at that moment are added and translations for this post.

I have a plugin worth Polylang.
In the internet I was looking for a solution for this task, seems to eat , but it does not fit, as I also need to get translation ID.

My code looks like this.

$ customfields = array (
  'name' = & gt; $ name
  'Surname' = & gt; $ Surname
  'email' = & gt; $ email
  'Position' = & gt; $ donorposition
  'Phone' = & gt; $ Phone
  'address' = & gt; $ address
  'Currency' = & gt; $ CURRENCYTYPE,
  'comment' = & gt; $ notes
  'paysystem' = & gt; $ payMethod,
  'Status' = & gt; 'pending',
  'ProjectID' = & gt; $ ProjectID,
  'amount' = & gt; $ amount
  'anonymous' = & gt; $ Anonymous,
  'Custom_amount' = & gt; $ customamount
  'Exchange' = & gt; $ Exchange.
);
$ postfields = array (
  'post_status' = & gt; 'Publish', // Post Status.
  'post_title' = & gt; 'Donated by'. $ Name. ' '. $ Surname, // Post Title.
  'post_type' = & gt; 'CustomPayments', // Post Type.
  'Meta_Input' = & gt; Array ('CustomPaymentsFields' = & GT; $ CustomFields) // Add Meta Fields
);
$ post_id = WP_INSERT_POST ($ postfields);

I need, therefore, to immediately add and transfers.

Thank you for the help!


Answer 1, Authority 100%

You have to create a translation as well as the main post

$ post_id_ru = wp_insert_post ($ postfieldsru);

and then specify Polylang that posts are associated:

$ translations = [
  'en' = & gt; $ post_id,
  'ru' = & gt; $ post_id_en
];
PLL_SAVE_POST_Translations ($ translations);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions