term_id, PostModel::TYPE_TERM, (string) $term->name, 'publish', (string) $term->slug ); } /** * Returns PostModels for a list of term IDs, in input order. * * Skips IDs that don't resolve to a term. Returns an empty array for * an empty input. * * @since 1.0.0 * * @param array $ids Term identifiers. * * @return array */ public function find_many( array $ids ): array { $out = array(); foreach ( $ids as $id ) { $model = $this->find( (int) $id ); if ( null !== $model ) { $out[] = $model; } } return $out; } /** * Returns the stored link counts for a term. * * @since 1.0.0 * * @param int $term_id Term identifier. * * @return array{inbound: int, outbound: int, external: int} */ public function get_link_counts( int $term_id ): array { return array( 'inbound' => (int) get_term_meta( $term_id, PostRepository::META_INBOUND_INTERNAL, true ), 'outbound' => (int) get_term_meta( $term_id, PostRepository::META_OUTBOUND_INTERNAL, true ), 'external' => (int) get_term_meta( $term_id, PostRepository::META_OUTBOUND_EXTERNAL, true ), ); } /** * Writes the link counts for a term. * * @since 1.0.0 * * @param int $term_id Term identifier. * @param int $inbound Inbound internal link count. * @param int $outbound Outbound internal link count. * @param int $external Outbound external link count. * * @return void */ public function update_link_counts( int $term_id, int $inbound, int $outbound, int $external ): void { update_term_meta( $term_id, PostRepository::META_INBOUND_INTERNAL, max( 0, $inbound ) ); update_term_meta( $term_id, PostRepository::META_OUTBOUND_INTERNAL, max( 0, $outbound ) ); update_term_meta( $term_id, PostRepository::META_OUTBOUND_EXTERNAL, max( 0, $external ) ); } }