Looper custom query with last 7 days

Hi there,

I have a custom post type “document” with some custom fields.
One field is called “datum” and I sort the posts with this date.

What I have right now:

post_type=document&orderby=meta_value&meta_key=datum&order=DESC&post_status=publish&ignore_sticky_posts=1

This works fine.
I now want to display the posts from the last seven days in relation to the date in the “datum” field. I can’t figute out how to do so.

Any suggestion?

Thank you,
Michael

Hi Michael,

Thanks for reaching out.
I would suggest you go through the following thread with a similar topic.

Please remember that you can’t calculate the date of the past seven days using the Dynamic Content tag used to compare the date in the query.

Hope it helps.
Thanks

@tristup:

Thank you.
I saw this discussion and similar. Unfortunately, they all discuss to show post after a certain date or before a certain date. That’s why they use “compare”
But I need to show posts the last 7 days. I only know "after=‘5 days’ but this works not with a custom field date.

Hi Michael,

In that case, I would suggest you create a custom Dynamic Content tag as shown in the example and the following thread. And return the date after calculating the seven days.

add_filter( 'cs_dynamic_content_seven', function( $result, $field, $args) {
    // {{dc:stuff:seven}}
    $result = 'dynamic value'; //calculate the seven days 
    return $result;
}, 10, 3 );

Hope it helps.
Thanks

Holy Moly! Never thought about this.
That’s a fantastic feature / filter.

Thank you so much. Things are getting easier :slight_smile:

Hi Michael,

Glad that we are able to help you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.