Title: PHP function or xPath?
Last modified: July 5, 2018

---

# PHP function or xPath?

 *  Resolved [alexnn](https://wordpress.org/support/users/alexnn/)
 * (@alexnn)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/php-function-or-xpath/)
 * Hi there,
    I need to prohibit importing all rows with irrelevant dates in the{
   date} field on rule “{date}”>=Today. Or how to exclude the import of CSV lines
   that do not meet this rule? How it is better to make xPath on the first step 
   or PHP function? Can you show an example of this php code how to do it? Please
   help me)
 * Thanks!
    -  This topic was modified 7 years, 11 months ago by [alexnn](https://wordpress.org/support/users/alexnn/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10470788)
 * Hi [@alexnn](https://wordpress.org/support/users/alexnn/)
 * Unfortunately, it is not possible to filter by date in the filtering options 
   section of the import. Instead, you’ll need to use the “wp_all_import_is_post_to_create”
   hook: [https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_is_post_to_create.php](https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_is_post_to_create.php).
 * Here’s an example snippet that you can adjust as needed:
 *     ```
       function my_is_post_to_create( $continue_import, $data, $import_id ) {
           if ( $import_id == 18 ) { // Change this to your actual import ID.
       		if ( strtotime( $data['date'] ) >= strtotime( "Today" ) ) {
       			return false;
       		} else {
       			return true;
       		}
       	}
           return true;
       }
       add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
       ```
   
 *  Thread Starter [alexnn](https://wordpress.org/support/users/alexnn/)
 * (@alexnn)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10478869)
 * Hi!
    Thanks for such support! Firstly I try to prepare a date from the string.
   I try this code
 *     ```
       $desc='{string[1]}';
       $data = preg_replace("/(.*?)((\d{1,2})-(\d{1,2})-(\d{4}))/i", "$5-$4-$3", $desc);
       $data = strtotime( $data );
       function my_is_post_to_create( $continue_import, $data, $import_id ) {
           if ( $import_id == 8 ) { // Change this to your actual import ID.
       		if ( $data >= strtotime( "Today" ) ) {
       			return false;
       		} else {
       			return true;
       		}
       	}
           return true;
       }
   
       add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
       ```
   
 * but all the records are skipped…SKIPPED: By filter wp_all_import_is_post_to_create….
   
   What could be wrong?
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10491625)
 * Hi [@alexnn](https://wordpress.org/support/users/alexnn/)
 * You’ll need to grab the date from within the $data array in the my_is_post_to_create
   function. Assuming that the date is in the import element {string[1]}, something
   like this should work:
 *     ```
       function my_is_post_to_create( $continue_import, $data, $import_id ) {
           $date = preg_replace("/(.*?)((\d{1,2})-(\d{1,2})-(\d{4}))/i", "$5-$4-$3", $data['string']);
           $date = strtotime( $date );
           if ( $import_id == 8 ) { // Change this to your actual import ID.
       		if ( $date >= strtotime( "Today" ) ) {
       			return false;
       		} else {
       			return true;
       		}
       	}
           return true;
       }
   
       add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3);
       ```
   
 *  Thread Starter [alexnn](https://wordpress.org/support/users/alexnn/)
 * (@alexnn)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10493492)
 * Hi!
    Unfortunately this code does not work. My {string[1]} contain “words blabla
   and date(d-m-Y format)”. What date format does the function $data understand?
   $data[‘format???’]
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10505810)
 * Hi [@alexnn](https://wordpress.org/support/users/alexnn/)
 * The $data variable is an array of your import elements and their values, it does
   not recognize or convert date formats. You must extract the date from the $data
   array and then parse it.
 * Keep in mind that the code we provided is only example code, you’ll need to adjust
   it to work with your data. We, unfortunately, can’t write custom code for your
   project.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP function or xPath?’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/php-function-or-xpath/#post-10505810)
 * Status: resolved