duanjieyi6582 2016-05-01 11:52
浏览 10
已采纳

如果title包含字符串'aaa','bbb'或'ccc'替换字段{category [1}

Hello gods of Stackoverflow,

Now i hate to be "that guy" who didnt search properly but i am running into a problem that i need a fix for and can't find a solution i can work with because of my lack in coding skills, my knowledge barely tickles the surface.

Here's the thing.

I am using a tool to import feeds into my website (WP all Import) as woocommerceproducts. But in the categorization the feed suppliers made errors which i want to tackle without emailing them everytime i stumble upon one.

i.e: the title contains words like satchel, bag, clutch etc but the product is categorized as 'jewellery > earrings' in the CSV or XML.

The import tool will ask me where to find the product category, i point it to the node {category[1]}

But when the category is missing or faulty i want it to check the title for certain words, and if present change the value of it to that found word.

something like: 

[if ({title[1]}contains "satchel") {
    category = "bags > satchel",
} else if ({title[1]} contains clutch) {
    category = "bags > clutch",
} else {
    category = {sub_category[1]} #the normal value if nothing was found 
}]

I just can't find the pieces to put the formatting together. I might need to work towards a function that i could expand to generate categories based solely out of presence of certain words in the title but maybe when i get better that would be an option.

I hope i was able to provide a clear view on the problem. The "[ ]" is there because thats how the plugin wants code to be entered instead of a {fieldname[1]}, another example below:

The following was an example of a problem i was able to fix: i needed to replace values like "0/3months/1/2months" to "0-3 months/1-2months" before i replaced the slash"/" with a pipe"|" for wordpress to recognize it as a seperate value.

[str_replace("/","|",
   str_replace("0/3","0-3",
     str_replace("1/2","1-2",
       str_replace("3/6","3-6",{size[1]}))))]

The fields can also be used to call functions but only in the 'pro' version of the plugin.

Any help is very much appreciated, thanks in advance.

  • 写回答

2条回答 默认 最新

  • duanchun5520 2016-05-01 12:00
    关注

    You could use strpos.

    Example:

    if (strpos($title, "satchel") !== false) {
        $category = "bags > satchel";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c