Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi jeffdoan06

    Is this a specific date or a period of time?

    Did you checkout the limit month parameter?
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/#limit-month

    Thread Starter jeffdoan06

    (@jeffdoan06)

    Yes this would work — we’ll prolly need to update it every month, but this’ll work. Is there a way to limit posts to only after X month?

    Thanks for the reply!

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Are you using the widget or shortcode, or both?

    Thread Starter jeffdoan06

    (@jeffdoan06)

    Neither — including it in functions.php

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Can you post the code you use in functions.php here.

    Thread Starter jeffdoan06

    (@jeffdoan06)

    add_filter( 'the_content', 'add_related_posts_after_post_content' );
    function add_related_posts_after_post_content( $content ) {
    
        //check if it's a single post page.
        if ( is_single() ) {
    
            // check if we're inside the main loop
            if ( in_the_loop() && is_main_query() ) {
    
                // add your own attributes here (between the brackets [ ... ])
                $shortcode = '[related_posts_by_tax posts_per_page="4" orderby="post_date"]';
    
                // add the shortcode after the content
                $content = $content . $shortcode;
            }
        }
    
        return $content;
    }

    Thanks — I just used sample code here, but I’m just trying to figure out the best filter to use here =)

    Thread Starter jeffdoan06

    (@jeffdoan06)

    Also how do I change the template used with the above function?

    Update: figured this part out =)

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Try changing this:

    // add your own attributes here (between the brackets [ ... ])
    $shortcode = '[related_posts_by_tax posts_per_page="4" orderby="post_date"]';

    To this:

    // add your own attributes here (between the brackets [ ... ])
    $shortcode = '[related_posts_by_tax posts_per_page="4" limit_month="1"]';

    This will search for related posts published in the last month.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Filter only posts after a certain date’ is closed to new replies.