WordPress 类别的 & 符号问题
我有一系列类别,其中一些带有 &即事件和娱乐。 我的脚本导入这些类别并使用其名称获取每个类别的 ID。 即:$cat_id = array(get_cat_id($linearray[0]),get_cat_id($linearray[1]),get_cat_id($linearray[2]),get_cat_id($linearray[3])); 然后,我的脚本使用这些类别 ID 将帖子添加到 wp。 我的问题是我使用 & 导入的类别;不是进口的。 这些相同的类别(当发送电子邮件通知时)会在&处破坏电子邮件。 有一个简单的解决方法吗?
I have an array of categories, some with an & i.e. events & entertainment.
My script imports these categories and gets the ID of each using its name.
i.e.: $cat_id = array(get_cat_id($linearray[0]),get_cat_id($linearray[1]),get_cat_id($linearray[2]),get_cat_id($linearray[3]));
My script then adds a post to wp using these category ID's.
My problem is that categories from my import with the & are not imported.
These same categories (when an email notice is sent) break the email at the &.
Is there a simple workaround to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当你写帖子时,你可以在那里写
&
而不是&
,它将被翻译为&
没有任何问题。您也可以使用
str_replace
函数将其转换为&
例如:When you are writing post, instead of
&
you can write&
there and it will be translated to&
without any problems.Also you could use the
str_replace
function to convert that to&
eg:我想在某些情况下我使用了我自己的 WordPress 自定义 sluggify 函数:
注意两行重复的行:
虽然重复,但非常必要!
对于下面无知的评论者 - 这是一个可重用的函数,您可以在其中传递任何字符串值,并且它将被猛击。因此,对于上述情况是可行的。
I think for some circumstances I used my own custom sluggify function for Wordpress:
Note the two repetitive lines:
Although repetitive, it's quite necessary!
For the ignorant commenter below - it's a reusable function where you can pass in any string value and it will be slugged. So, workable for the above case.
有一个 WP 内置函数可以实现此目的:
来自 文档:
There is a WP built-in function for this:
From the documentation: