How to use Xpath to filter out date field in Wordpress plugin?

烈酒焚心 提交于 2021-01-07 02:44:46

问题


I am using the WP All Import plugin to import a csv file with thousands of records every day but I don't need all of them, only the ones that have been updated. There is a "last modified" column in the csv file which i'd like to compare to today's date and filter out anything that doesn't match.

Wp all import let's you do this using xpath, but I have no idea how to reference today's date in it, can anyone help?

WP All Import xpath screen.png

Kind Regards,


回答1:


XPath 2.0 solution (paste it in the XPath field) to keep records of the day:

/node[@last_modified[concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

We extract the date with substring, convert the current date (XPath 2.0 functions : not sure WP supports it) to string and we compare them. We finally put this condition between brackets.

EDIT : OK. last_modified is an element not an attribute. So just remove the "@" from the expression :

/node[last_modified[concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

If it doesn't work just add '[1]' after the element :

/node[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]

EDIT 2 : To be complete, to keep records of the day with XPath 1.0, you have to enter manually the date of the day ("20190820" in the examples below, change it accordingly)

//*[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=20190820]]
/node[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=20190820]]

With XPath 2.0, the process to check the date should be automatic (but it seems the plugin doesn't support it) :

//*[last_modified[1][concat(substring(.,7,4),substring(.,4,2),substring(.,1,2))=string(format-date(current-date(),"[Y][M01][D01]"))]]


来源:https://stackoverflow.com/questions/60883768/how-to-use-xpath-to-filter-out-date-field-in-wordpress-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!