ansonphong / postworld

Wordpress Theme Development Framework
GNU General Public License v2.0
7 stars 0 forks source link

pw_insert_terms() - Function #57

Closed ansonphong closed 11 years ago

ansonphong commented 11 years ago

Hi Haidy, Here is a function which we can create which will make it very easy to insert terms from an array, incase we need to do multiple times testing when doing data migration. I have already got some terms arrays here for testing, I will post them below.

pw_insert_terms() https://github.com/phongmedia/postworld/tree/master/php#pw_insert_terms--terms_array-input_formatforce_slugs-

Please note to add this to the "RSV2-data-migration" service tab with Innuva, as it technically falls outside of Postworld development, even though it makes sense to include it in the Postworld Library for future use.

Let me know if you have any questions about the function.

ansonphong commented 11 years ago

Here is the object to add, in terms of a Javascript object.


tax_terms = {
        "topic" : [
            {
                slug:"psyche",
                name:"/psyche",
                children:{
                    ancient:"Ancient Mysteries",
                    astrology:"Astrology",
                    consciousness:"Consciousness",
                    dreams:"Dreams",
                    ets:"Extraterrestrials",
                    indigenous:"Indigenous Cultures",
                    occult:"Occult",
                    psi:"Psi",
                    psychedelics:"Psychedelics",
                    psychology:"Psychology",
                    shamanism:"Shamanism",
                    spirituality:"Spirituality",
                    transformation:"Transformation",
                    psyche_misc:"Misc"
                    },
            },
            {
                slug:"arts",
                name:"/arts",
                children:{
                    conferences:"Conferences",
                    digital_art:"Digital Art",
                    world_art:"World Art",
                    festival_culture:"Festival Culture",
                    games:"Games",
                    music:"Music",
                    performance:"Performance",
                    publications:"Publications",
                    video:"Video",
                    film:"Film",
                    misc:"Misc"
                    },
            },
            {
                slug:"body",
                name:"/body",
                children:{
                    energy_medicine:"Energy Medicine",
                    food_nutrition:"Food & Nutrition",
                    healing:"Healing",
                    herbalism:"Herbalism",
                    homeopathy:"Homeopathy",
                    sexuality:"Sexuality",
                    slow_living:"Slow Living",
                    tantra:"Tantra",
                    yoga:"Yoga",
                    body_misc:"Misc",
                    },
            },
            {
                slug:"eco",
                name:"/eco",
                children:{
                    animal_rights:"Animal Rights",
                    climate_change:"Climate Change",
                    conservation:"Conservation",
                    energy:"Energy",
                    environment:"Environment",
                    extinction:"Extinction",
                    gardening:"Gardening",
                    permaculture:"Permaculture",
                    sustainability:"Sustainability",
                    water:"Water",
                    eco_misc:"Misc",
                    },
            },
            {
                slug:"tech",
                name:"/tech",
                children:{
                    biomimicry:"Biomimicry",
                    cosmology:"Cosmology",
                    design_science:"Design Science",
                    digital:"Digital",
                    diy:"DIY",
                    networks:"Networks",
                    privacy:"Privacy",
                    robotics:"Robotics",
                    singularity:"Singularity",
                    tech_misc:"Misc"
                }
            },
            {
                slug:"commons",
                name:"/commons",
                children:{
                    action_alerts:"Action Alerts",
                    activism:"Activism",
                    alternative_economics:"Alternative Economics",
                    collaboration:"Collaboration",
                    community:"Community",
                    crowdfunding:"Crowdfunding",
                    democracy:"Democracy",
                    drug_laws:"Drug Laws",
                    evolver:"Evolver",
                    evolver_spores:"Evolver Spores",
                    open_source:"Open Source",
                    peer_to_peer:"Peer to Peer",
                    retreats:"Retreats",
                    commons_misc:"Misc"
                }
            },
        ],
        'section' : [
            {
                slug:"psychedelic",
                name:"Psychedelic Culture",
            },
            {
                slug:"conscious_convergences",
                name:"Conscious Convergences",
            },
            {
                slug:"psi",
                name:"Psi Frontiers",
            },
            {
                slug:"video",
                name:"Videos",
            },
            {
                slug:"podcast",
                name:"Podcasts",
            },
            {
                slug:"edm",
                name:"Evolver EDM",
            },
            {
                slug:"evo_network",
                name:"Evolver Network",
            },
            {
                slug:"evo_learning_lab",
                name:"Evolver Learning Lab",
            },

        ],
hmikhail commented 11 years ago

I have some questions here: In the process: If a term* with the same slug already exists within a different taxonomy If $force_slugs == true, change the ** other ** slug - appending an incremental number

1- Do you mean that we insert a new term with the slug "slugname1" ? and then insert the children? 2- If the term doesn't exist at all. Should we insert it and its children?

ansonphong commented 11 years ago
  1. YES - you understand exactly. Even better slugname-1. The old force-over-written slug keeps the same ID, thus keeping it's references, and the new one takes it's slug.
    This would only be used the first time running the script, generally, to make sure it doesn't clash with other terms.
  2. Yes, if the term doesn't exist at all with that slug, then create it and insert the children.
ansonphong commented 11 years ago

Keep in mind for the question #1, that only applies if the term is of a DIFFERENT TAXONOMY. For instance, if you're inserting 'topic' terms and a 'post_tag' term with the same slug already exists. Otherwise, if it already exists in the same taxonomy, then keep it without renaming and just skip adding it, but add the children to that term ID.

hmikhail commented 11 years ago

Does this rule apply also to children? I can see that the same term can have multiple parents.

ansonphong commented 11 years ago

Yes, please also apply to the children.

On Mon, Oct 28, 2013 at 4:52 AM, hmikhail notifications@github.com wrote:

Does this rule apply also to children?

— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/57#issuecomment-27205330 .