Tryin to Filter Posts by Date
-
Hello,
I’m trying to use the code here (https://www.wpallimport.com/documentation/developers/code-snippets/#filter-posts-by-date) to update only some posts with certains dates of a recurring import.
The result is that all posts are skipped, even those that should be updated
Here is the code i’m using
function filter_by_date( $continue_import, $data, $import_id ) { $import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) ); if ( in_array( $import_id, [12, 23] ) ) { // Change 'column_4' to your file's date field. $date_in_file = strtotime( $data['last_mod'] ); // Change '2018-10-10' to your real target date. $date = "2021-04-28 00:00:00"; // Convert specified date to Unix timestamp. $target_date = strtotime($date); // Compare file date with target date. if ( $date_in_file >= $target_date ) { // Create or update record if file date >= target date. return true; } else { // Do not create or update the record otherwise. return false; } } // Take no action for other import IDs. return $continue_import; } // Apply the code to posts set to be created. add_filter('wp_all_import_is_post_to_create', 'filter_by_date', 10, 3); // Apply the code to posts set to be updated. add_filter('wp_all_import_is_post_to_update', 'filter_by_date', 10, 3);And this is the format of {last_mod[1]}: 2021-04-28 12:15:30
I also enabled debugging and it get this warning:
PHP Warning: Illegal string offset ‘last_modified’
So, is there any way to make it work?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Tryin to Filter Posts by Date’ is closed to new replies.