Inpsyde\MultilingualPress\API\WPDBContentRelations::relate_all_posts PHP Method

relate_all_posts() public method

This method is suited to be used after site duplication, because both sites are assumed to have the exact same post IDs. Furthermore, the current site is assumed to be either the source site or the destination site.
Since: 3.0.0
public relate_all_posts ( integer $source_site_id, integer $destination_site_id ) : integer
$source_site_id integer Source site ID.
$destination_site_id integer Destination site ID.
return integer The number of relations inserted.
    public function relate_all_posts($source_site_id, $destination_site_id)
    {
        $inserted = 0;
        // TODO: Restrict to "supported post types", and improve post status (e.g., `NOT IN ('trash', 'auto-draft')`?).
        $query = "\nINSERT INTO {$this->table} (\n\tml_source_blogid,\n\tml_source_elementid,\n\tml_blogid,\n\tml_elementid,\n\tml_type\n)\nSELECT %d, ID, %d, ID, 'post'\nFROM {$this->db->posts}\nWHERE post_status IN ('publish', 'future', 'draft', 'pending', 'private')";
        foreach ([$source_site_id, $destination_site_id] as $site_id) {
            $inserted += (int) $this->db->query($this->db->prepare($query, $source_site_id, $site_id));
        }
        return $inserted;
    }