• Resolved axelmktg

    (@axelmktg)


    I have a custom field with a date, that i would like to filter based on “older than” and “newer than” rules. The custom filed is selected and it has the following format mm/dd/yyyy. I had tried to filter with ‘today’, date(“m/d/Y”,strtotime(“today”)) and strtotime(“today”) to produce needed results.
    Neither has worked, please advise on a solution.

    Axel.

    https://wordpress.org/plugins/wp-all-export/

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi Axel.

    This would be possible using our API, specifically the ‘wp_all_export_csv_rows’ hook. Here’s some example code that will exclude any post with a date older than today:

    add_filter( 'wp_all_export_csv_rows', 'wpae_csv_rows', 10, 1 );
    function wpae_csv_rows( $articles )
    {
        foreach ( $articles as $key => $article ) {
            if ( ! empty( $article['Date Field'] )  )
            {
                $date1 = $article['Date Field'];
                $date2 = date( "m/d/Y", time() );
    
                if ( strtotime( $date1 ) < strtotime( $date2 ) ) {
                    unset( $articles[$key] );
                }
            }
        }
        return $articles;
    }

    You can place this code in the Function Editor via All Export > Settings.

    To use this code, you’ll need to add the custom field to your export template and use the value “Date Field” for the setting “What would you like to name the column/element in your exported file?” (click the element to find that setting).

Viewing 1 replies (of 1 total)

The topic ‘Filter by custom field with a date’ is closed to new replies.