问题
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