M
M
Mariolis2017-07-06 00:42:36
JavaScript
Mariolis, 2017-07-06 00:42:36

Why is the polylang connection between posts not saved?

There is a simple plugin like this:

add_action ('save_post', 'foo');


function foo($post_id){ 
  global $polylang;
  $eng_id = pll_get_post($post_id, 'en');
  if (!$eng_id) {
    $post = get_post($post_id);
    $eng_post_params = [
      'post_title'   => $post->post_title . '-eng',
      'post_date'    => date( 'Y-m-d H:i:s' ),
      'post_type'    => 'gun_model',
      'post_status'  => 'publish',
    ];
    // Удаляем хук, чтобы не было зацикливания
    remove_action( 'save_post', 'saveCustomField' );
    $eng_id = wp_insert_post( $eng_post_params, true );
    // Ставим хук обратно
    add_action( 'save_post', 'saveCustomField' );
    $polylang->model->post->set_language($eng_id, 'en');
//		pll_save_post_translations([
//			'ru' => $post_id,
//			'en' => $eng_id
//		]);
    $polylang->model->save_translations('gun_model', $post_id, array('en' => $eng_id));
  }

}

Its task is to create a post like 'gun_model' in English if there is no such page.
Everything works except for the very end: a record of the required type is created, the language is assigned to English, but the connection between the saved post and the new post in English is not saved for some reason not by the function that is used now, not the one that is commented out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-12-20
@dragonika8

When you click on a point, you are passing it to photoClick, and you are trying to access the data-* properties of the clicked object. And the dot doesn't have them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question