Last active
January 8, 2016 14:27
-
-
Save carbontwelve/6311497 to your computer and use it in GitHub Desktop.
Laravel model for wordpress wp_term table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Import.php */ | |
namespace App/Controllers; | |
use /App/Models/TermTaxonomy; | |
use /App/Models/Term; | |
class Import extends BaseController | |
{ | |
public function index() | |
{ | |
/* Get all categories */ | |
$terms = TermTaxonomy::with( | |
array( | |
'parent', | |
'parent.term' | |
'term' | |
) | |
) | |
->where('parent', 0) | |
->where('taxonomy','category') | |
->get(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Term.php */ | |
namespace App/Models; | |
class Term extends Eloquent | |
{ | |
protected $table = 'wp_terms'; | |
protected $primaryKey = 'term_id'; | |
public function taxonomy() | |
{ | |
return $this->hasOne('/App/Models/TermTaxonomy', 'term_id'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* TermTaxonomy.php */ | |
namespace App/Models; | |
class TermTaxonomy extends Eloquent | |
{ | |
protected $table = 'wp_term_taxonomy'; | |
protected $primaryKey = 'term_taxonomy_id'; | |
public function term() | |
{ | |
return $this->belongsTo('/App/Models/Term', 'term_id'); | |
} | |
public function children() | |
{ | |
return $this->hasMany('/App/Models/TermTaxonomy', 'parent'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment