Inpsyde\MultilingualPress\API\ContentRelations::get_relations PHP Method

get_relations() public method

Return an array with site IDs as keys and content IDs as values.
public get_relations ( integer $source_site_id, integer $source_content_id, string $type = 'post' ) : array
$source_site_id integer Source blog ID.
$source_content_id integer Source post ID or term taxonomy ID.
$type string Content type.
return array
    public function get_relations($source_site_id, $source_content_id, $type = 'post');

Usage Example

 /**
  * Updates the trasher setting of the post with the given ID as well as all related posts.
  *
  * @since   3.0.0
  * @wp-hook save_post
  *
  * @param int     $post_id Post ID.
  * @param WP_post $post    Post object.
  *
  * @return int The number of posts updated.
  */
 public function update_settings($post_id, WP_Post $post)
 {
     if (!$this->nonce->is_valid()) {
         return 0;
     }
     if (!in_array($post->post_status, ['publish', 'draft'], true)) {
         return 0;
     }
     $value = array_key_exists(TrasherSettingRepository::META_KEY, $_POST) ? (bool) $_POST[TrasherSettingRepository::META_KEY] : false;
     if (!$this->setting_repository->update($post_id, $value)) {
         return 0;
     }
     $current_site_id = get_current_blog_id();
     $related_posts = $this->content_relations->get_relations($current_site_id, $post_id, 'post');
     unset($related_posts[$current_site_id]);
     if (!$related_posts) {
         return 1;
     }
     $updated_posts = 1;
     array_walk($related_posts, function ($post_id, $site_id) use(&$updated_posts, $value) {
         switch_to_blog($site_id);
         $updated_posts += $this->setting_repository->update($post_id, $value);
         restore_current_blog();
     });
     return $updated_posts;
 }
All Usage Examples Of Inpsyde\MultilingualPress\API\ContentRelations::get_relations