我正在尝试查看帖子(thru id)是否有指定的标记
if has_tag( $tag = \'Cat\', $post = $post_id ) {
$taganimal = "Cat";
}
我尝试了这个,但它只是使网站崩溃。从中获得想法https://developer.wordpress.org/reference/functions/has_tag/, 但无法使其工作。。
我正在尝试查看帖子(thru id)是否有指定的标记
if has_tag( $tag = \'Cat\', $post = $post_id ) {
$taganimal = "Cat";
}
我尝试了这个,但它只是使网站崩溃。从中获得想法https://developer.wordpress.org/reference/functions/has_tag/, 但无法使其工作。。
您应该根据PHP语法用括号将条件括起来:
if (has_tag(\'Cat\', $post_id)) {
$taganimal = "Cat";
}
如果需要检查多个标记,可以使用foreach ([\'Cat\', \'Dog\'] as $animal) if (has_tag($animal, $post_id)) {
$taganimal = $animal;
break;
}
但如果帖子中有几个标签,它只能找到数组中列出的第一个标签。$notifications->have\\u posts()返回false,但我确信数据库中很少有这种自定义类型的帖子add_action(\'user_register\',\'jq_after_user_register_hook\', 10, 1); function jq_after_user_register_hook( $user_id ){ global $wpdb; $user_meta = get_userdata($user_id);&#