views:

268

answers:

3

I have 2 websites with similar content types.

Let's say an event-content type with some cck fields in it.

site1: events ( title, body, image ) site2: events ( title, body, image, onsite1)

by the extra field at site2-events i want to give the possibility to the user to post his event on the ( main ) site1.

Site1 and site2 are both on 1 database, although tables from site2 are prefixed.

How can i add content made from site2 to site1? ( Is there an easy way to do this without resorting to sql? I am using the nodeapi at this time to do some extra when an event is submitted. )

+1  A: 

Since you say you're already using hook_nodeapi it seems like you could just do:

if ($op == 'insert' && (see if checkbox is checked here))

...then switch to the other site's database, do a node_save, and switch back to the current site's database to let Drupal finish its business.

Mike Crittenden
Both websites are in 1 database because some tables (taxonomy) are shared. The tables of site2 are prefixed. , so the switch of database using db_set_active() won't work. Unless i've missed something. I'll have a look at your link asap.
Jozzeh
A: 

Lots of people use Feed API / Feeds module for this. You can filter by taxonomy terms, content type, whatever you need so that you don't have to import everything from the primary site. Great tool.

alxp
Will have a look at it. thx
Jozzeh
+1  A: 

You might be able to use db_set_active() as Mike-Crittenden describes even if it is within same database, as both $db_url and $db_prefix can be arrays, instead of single strings.

This way you can have the same db_url for both 'default' and 'alternative' db, but use different prefixes to switch between databasees using db_set_active('alternative') and db_set_active() to return to default.

digitalsean