Skip to content

Instantly share code, notes, and snippets.

@Programmer095
Forked from m-thomson/import-if-syntax.md
Created October 12, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Programmer095/48b6d12dee9c35d04e23d7cc4619b0e2 to your computer and use it in GitHub Desktop.
Save Programmer095/48b6d12dee9c35d04e23d7cc4619b0e2 to your computer and use it in GitHub Desktop.

WP All Import - IF/ELSE statement examples

Here are some example WP All Import [IF] statements. The criteria for an IF statment is written in XPath 1.0 syntax and can use XPath functions. Although powerful, XPath syntax can be quite complex. In many cases it might be easier to use a PHP function as shown here.

The [ELSE]<something> part is optional

Number is equal to:

[IF({price[.=0]})]Zero[ELSE]Not Zero[ENDIF]

Number is greater than:

[IF({price[.>0]})]Greater than 0[ENDIF]

Text is equal to:

[IF({title[.='Foo']})]The title is Foo[ENDIF]

Text is not equal to:

[IF({title[.!='Foo']})]The title is not Foo[ENDIF]

Text is empty (see note below):

[IF({title[.='']})]The title is empty[ENDIF]

Text contains:

[IF({title[contains(.,’Foo')]})]Has foo[ENDIF]

Text length is:

[IF({title[string-length()>10]})]{title}[ENDIF]

IF/ELSE example:

[IF({title[.='']})]The title is empty[ELSE]{title}[ENDIF]

Note: You might have seen examples using not(text()) to check for empty fields. While this is valid XPath syntax, it seems to fail on some servers. The reasons are unclear. Just use the Text is empty syntax above instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment