Home Forums Newsletter Plugin Support Filter WP posts by date

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #355849
    User
    Participant

    I am testing Newsletter Plugin and am very impressed!

    Can you confirm that there is no way to filter WP posts by date? I must be able to do this to prevent “stale” posts from appearing in the newsletter.

    I’m hoping there is a way!

    Thanks,
    Dan Hotchkiss

    #356015
    Michael
    Keymaster

    Hello Dan,

    thanks for the kind words. At the moment no, there’s no way to filter posts by date. Can you please explain to me what you mean by “stale” content?

    Thanks,
    Michael

    #356021
    User
    Participant

    Hi Michael,

    I send a weekly e-newsletter based on our website at http://www.uumiddleboro.org. Our minister writes a monthly column, which stays on the website for 11 days and then disappears. I do to do something similar in the weekly newsletter, so the same column does not appear repeatedly after it has gone “stale.” In addition to choosing a category and limiting the number of posts shown, I want to limit the amount of time before they disappear.

    To automate the disappearance of a post from the website, I use the code snippet below, which enables me to add to any query block a CSS class called since-xx-days-ago that chooses only posts that are less than xx days old.

    I hope this clarifies what I am looking for! It is similar to the “Range” setting in the Events Calendar block, but applied to the publication date of the post.

    Thanks,
    Dan

    add_filter( ‘generateblocks_query_wp_query_args’, function( $query_args, $attributes ) {
    if ( is_admin() || empty( $attributes[‘className’] ) ) {
    return $query_args;
    }
    // Look for a class like: since-20-days-ago, since-7-days-ago, etc.
    if ( preg_match( ‘/since-(\d+)-days-ago/’, $attributes[‘className’], $matches ) ) {
    $days = absint( $matches[1] ); // e.g. 20
    $query_args[‘date_query’] = array(
    array(
    ‘after’ => “{$days} days ago”,
    ),
    );
    }
    return $query_args;
    }, 10, 2 );

    #356112
    Michael
    Keymaster

    Hello Dan,

    I understood what you’re doing with the code snippet you’ve pasted but there’s no similar function in Newsletter, unfortunately. If you need to prevent older posts from being imported in a newsletter, at the moment there’s only the option to select “last xx posts.. from xx category”. It’s not checking for a temporal range, but it works in chronological order only. Anyway, I’ll talk about this feature requests with our developers, if proven useful (well, I know it is) we will discuss of implementing it in one of the future updates.

    Thanks for your precious feeback!


    From time to time, we ask our users to rate Newsletter based on their experience: every feedback means the world for us. If you have 5 minutes, here’s the link: https://bit.ly/please-rate-newsletter. A wordpress.org account is required. Thank you!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.