• I am trying to add a filter to this pod’s feed so that old events won’t show. Here’s my code in functions.php:

    function date_filter_function($query_args){
    $today = date(‘Ymd’);
    $query_args[‘meta_key’] = ‘date_of_event’;
    $query_args[‘meta_compare’] = ‘>=’;
    $query_args[‘meta_value_num’] = $today;

    return $query_args;
    }

    add_filter(‘date_filter’, ‘date_filter_function’);

    I’m fairly certain the reason this isn’t working is because the ‘date_of_event’ custom field in the pod does not return the date in the same format (‘Ymd’) as the $today variable I created. Does anyone know how to change the format of the date within the filter for each post? That way, the greater than or equal to comparison will actually make sense.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    date() is the right function, but the passed format has to exactly match the format Pods stores its event dates in, including any punctuation. I’m unsure what that might be, but an example that matches the format of the post_date property is date('Y-m-d H:i:s'), which returns something like “2021-01-18 17:33:44”

    Thread Starter seanmk011289

    (@seanmk011289)

    @bcworkz Thanks for the reply!

    Do you know if there’s a way to convert the returned date format I get from Pods to “Ymd”? I’m fairly new to PHP and don’t exactly know what I’m doing, but I feel like I’m getting close to a solution.

    Thanks!

    Moderator bcworkz

    (@bcworkz)

    There is almost always a way, but it may not be a very good way. One could hack the Pods code directly, but that’s ill advised. Ideally there would be a filter hook we could use. I’ve no idea if one exists, you’d have to ask in the Pods support forum.

    I’d think it’d be easier to match your code to whatever Pods does by default. You can verify how dates are stored through the phpMyAdmin app, which gives you direct access to the DB. Search the postmeta table for the meta key name of the field you want to query against.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating Date Filter w/ Pods’ is closed to new replies.