我正在尝试在创建分类法时实用地添加分类法术语。我尝试添加
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {BehaviorSubject} from 'rxjs';
import {map} from 'rxjs/operators';
import {JwtHelperService} from '@auth0/angular-jwt';
import { environment } from '../../environments/environment';
import { User } from '../_models/user';
@Injectable({
providedIn: 'root'
})
export class AuthService {
baseUrl = environment.apiUrl + 'auth/';
jwtHelper = new JwtHelperService();
decodedToken: any;
currentUser: User;
photoUrl = new BehaviorSubject<string>('../../assets/user.png');
currentPhotoUrl = this.photoUrl.asObservable();
this.changeMemberPhoto(this.currentUser.photoUrl);
constructor(private http: HttpClient) { }
changeMemberPhoto(photoUrl: string) {
this.photoUrl.next(photoUrl);
}
login(model: any) {
return this.http.post(this.baseUrl + 'login', model).pipe(
map((response: any) => {
const user = response;
if (user) {
localStorage.setItem('token', user.token);
localStorage.setItem('user', JSON.stringify(user.user));
this.decodedToken = this.jwtHelper.decodeToken(user.token);
this.currentUser=user.user;
this.changeMemberPhoto(this.currentUser.photoUrl);
}
})
);
}
register (model: any) {
return this.http.post(this.baseUrl + 'register', model);
}
loggedIn() {
const token = localStorage.getItem('token');
return !this.jwtHelper.isTokenExpired(token);
}
}
到wp_insert_term(
'A00', // the term
'we_colors'
);
,但这并未添加术语tax_color_palletes
。我正在编写此代码段;我该如何解决?
A00
答案 0 :(得分:0)
您是否要将term
添加到taxonomy
或post_type
中?
在您的示例中,您将taxonomy
'women_models'注册到了post_type
'we_colors'中。
但是随后您调用wp_insert_term
(需要taxonomy
)并将其传递给post_type
。哪个应该给你一个错误。
如果仅要将term
添加到taxonomy
,则需要将taxonomy
传递到wp_insert_term
。
wp_insert_term('A00', 'women_models');
如果相反,您实际上是想在post_type中添加术语,则应使用wp_set_object_terms
,后者可以依次调用wp_insert_term
来创建新术语。不过,您需要先获取$object_id
。
wp_set_object_terms( $object_id, ['term_1', 'term_2'], 'taxonomy_name');
https://developer.wordpress.org/reference/functions/register_taxonomy/ https://developer.wordpress.org/reference/functions/wp_insert_term/ https://developer.wordpress.org/reference/functions/wp_set_object_terms/