Skip to content

Commit

Permalink
support meta
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Nov 15, 2023
1 parent cfe6003 commit 1bba46a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ private function insert_initial_term( $term ) {
}
$args['parent'] = absint( $term_id );
}
wp_insert_term( $term->name, $this->name, $args );
$result = wp_insert_term( $term->name, $this->name, $args );
if ( $result['term_id'] ) {
foreach ( $term->meta as $meta_key => $meta_value ) {
add_term_meta( $result['term_id'], $meta_key, $meta_value, true );
}
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Term {
*/
public $alias_of;

/**
* Meta data.
* @var array
*/

public $meta = array();

/**
* Term constructor.
*
Expand All @@ -56,7 +63,7 @@ class Term {
* @param string $description Description.
* @param string $alias_of alias slug.
*/
public function __construct( $name = '', $slug = '', $parent = 0, $description = '', $alias_of = '' ) {
public function __construct( $name = '', $slug = '', $parent = 0, $description = '', $alias_of = '', $meta = array() ) {
$this->name = $name;
if ( empty( $slug ) ) {
$slug = $name;
Expand All @@ -65,5 +72,6 @@ public function __construct( $name = '', $slug = '', $parent = 0, $description =
$this->parent = $parent;
$this->description = $description;
$this->alias_of = $alias_of;
$this->meta = $meta;
}
}

0 comments on commit 1bba46a

Please sign in to comment.