• Resolved ibreezer

    (@ibreezer)


    Hi
    I’m creating an import script with multilanguage support, and to make it work I need to know how the wp_terms value e.g. “pl_********” are created, so I can create them on the fly when data is important from another cms. Just refer me to the right page I would appreciate it alot. Or if you like show me the function right here any other suggestion is welcome aswell.

    Regards

    https://www.ads-software.com/plugins/polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ibreezer

    (@ibreezer)

    Oki I’ve come up with this code so far but It still not working, what am I missing?

    $term = uniqid('pll_'); // the term name
    $this->wcmysql->query("INSERT INTO ".$this->wcpre."terms (slug, name) VALUES ('".$term."','".$term."')");
    $term_id = $this->wcmysql->insert_id;//get term id
    (string) $insert;
    foreach($langs as $lang){
    $insert .= "('".$lang."','".$term_id."','0'),";//langs has postids for all translations for the post
    }
    $insert = rtrim($insert, ",");
    $this->wcmysql->query("INSERT INTO ".$this->wcpre."term_relationships (object_id, term_taxonomy_id,term_order) VALUES ".$insert)or die('MYSQL ERROR: '.$this->wcmysql->error);
    $desc =serialize(array('en'=>(int)$langs[1],'sv'=>(int)$langs[2]));//serialize relationship
    $this->wcmysql->query("INSERT INTO ".$this->wcpre."term_taxonomy (term_id, taxonomy,description,count) VALUES ('".$term_id."','post_translations','".$desc."','".count($langs)."')")or die('MYSQL ERROR: '.$this->wcmysql->error);

    everything get insert and compare to another post I’ve done manually it has the exact same data in the database but it still doesn’t get couple with eachother…

    Thread Starter ibreezer

    (@ibreezer)

    Solved it by using the build in functions

    pll_set_post_language($langs[1],'en');
    		pll_set_post_language($langs[2],'sv');
    		pll_save_post_translations(array('en'=>$langs[1],'sv'=>$langs[2]));

    but I had to load wp core aswell inside my script which i rather wouldnt…

    Plugin Author Chouby

    (@chouby)

    Hi!

    If you want an example of code (almost) completely in sql, you can look at the code of WPML to Polylang: https://www.ads-software.com/plugins/wpml-to-polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How is "*_terms" value create in the db?’ is closed to new replies.