Inpsyde\MultilingualPress\API\WPDBContentRelations::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')
    {
        $cache_key = $this->get_cache_key($source_site_id, $source_content_id, $type);
        $cache = wp_cache_get($cache_key, $this->cache_group);
        if (is_array($cache)) {
            return $cache;
        }
        $sql = "\nSELECT t.ml_blogid as site_id, t.ml_elementid as content_id\nFROM {$this->table} s\nINNER JOIN {$this->table} t\nON s.ml_source_blogid = t.ml_source_blogid\n\tAND s.ml_source_elementid = t.ml_source_elementid\n\tAND s.ml_type = t.ml_type\nWHERE s.ml_blogid = %d\n\tAND s.ml_elementid = %d\n\tAND s.ml_type = %s";
        $query = $this->db->prepare($sql, $source_site_id, $source_content_id, $type);
        $results = $this->db->get_results($query, ARRAY_A);
        if (!$results) {
            return [];
        }
        $output = [];
        foreach ($results as $set) {
            $output[(int) $set['site_id']] = (int) $set['content_id'];
        }
        wp_cache_set($cache_key, $output, $this->cache_group);
        return $output;
    }