Closed ansonphong closed 11 years ago
When I do json_decode to your json, and run json_last_error() it gives number 4 which maps to 4 = JSON_ERROR_SYNTAX.
I think you json should look as follows (so that when decoding the json it gives the specified array structure)
$test ='{
"topic": [
{
"slug": "psyche",
"name": "\/psyche",
"children": {
"ancient": "Ancient Mysteries",
"astrology": "Astrology",
"consciousness": "Consciousness",
"dreams": "Dreams",
"ets": "Extraterrestrials",
"indigenousv": "Indigenous Cultures",
"occult": "Occult",
"psi": "Psi",
"psychedelics": "Psychedelics",
"psychology": "Psychology",
"shamanism": "Shamanism",
"spirituality": "Spirituality",
"transformation": "Transformation",
"psyche_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": "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"
}
],
"type": [
{
"slug": "song_week",
"name": "Song of the Week",
"parent_name": "Hilight",
"parent": "hilight"
},
{
"slug": "video_week",
"name": "Video of the Week",
"parent_name": "Hilight",
"parent": "hilight"
}
]
}';
print_r(pw_insert_terms($test,'JSON', true))
Ok great, that seems to be adding them now.
Strangely, they seem to be appearing in some of the places I'm getting them, and other places they're not. Also in the Wordpress Admin, they're not all showing up in the term editor - they show up like... nothing. I'll try and investigate the cause of this.
Is this happening to you? Closing the issue for now.
Oh yes I see, my JSON was pretty sloppy with extra commas and no \ before /. Thanks.
That last issue got fixed now too somehow. Seems to be working well, excellent.
Hi Haidy, I've tried copy and pasting your test code exactly, although I haven't been able to get this function to work correctly. It gives this warning every time and no terms are added
Warning: get_object_vars() expects parameter 1 to be object, array given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 246
Warning: array_keys() expects parameter 1 to be array, null given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 247
Warning: get_object_vars() expects parameter 1 to be object, array given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 246
Warning: array_keys() expects parameter 1 to be array, null given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 247
Warning: get_object_vars() expects parameter 1 to be object, array given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 246
Warning: array_keys() expects parameter 1 to be array, null given in /Users/phong/Projects Clients/Reality Sandwich/_WEB/RSV2/WORDPRESS/wp-content/plugins/postworld/php/postworld_taxonomies.php on line 247
I solved this issue, but there is another question, what happens if the taxonomy is invalid? In the input specified above, topic and section are invalid taxonomies.
If the taxonomy itself is invalid, then just skip over it.
On 2013-11-03, at 3:48 AM, hmikhail notifications@github.com wrote:
I solved this issue, but there is another question, what happens if the taxonomy is invalid? In the input specified above, topic and section are invalid taxonomies.
— Reply to this email directly or view it on GitHub.
Hi Haidy, So I'm trying to use
pw_insert_terms()
here to insert an array of terms into the DB - this will be a very helpful function.Although, what happens is nothing happens when I run it.
So I insert it like this, with a well formed JSON object.
But then this is the error that is coming :
Any ideas?