[Support request] Show newest/latest products each week

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Show newest/latest products each week

This topic contains 1 reply, has 2 voices, and was last updated by  Tom 6 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9547

    Robyn
    Participant

    First, is there a list of filters/actions somewhere that shows what I can hook into?

    Second, I want to show a list of the newest products from that are no more than a week old.
    Under More Settings, I have Order=Descending; Order by=Modified; Status=Published; Meta Key=_stock_status; Meta value=instock; Tax operator=IN

    I need to limit the posts this shows to only from the past week.
    I found this snippet that might work, but I’m not sure what action/filter to use.

    $week = date( ‘W’ );
    $year = date( ‘Y’ );
    $query = new WP_Query( ‘year=’ . $year . ‘&w=’ . $week );

    -Robyn
    https://lovecanary.ca/new-arrivals

    #9551

    Tom
    Keymaster

    Hi there,

    This is the filter you need: https://github.com/tomusborne/wp-show-posts/blob/release/1.2/wp-show-posts.php#L383

    It’s only in 1.2 at the moment, which you can download from GitHub.

    Then your function would be:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 123 === $settings['list_id'] ) {
            $week = date( 'W' );
            $year = date( 'Y' );
    
            $args['w'] = $week;
            $args['year'] = $year;
        }
    
        return $args;
    }, 10, 2 );

    You just need to update 123 with the ID of your list.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.