Created
September 28, 2021 16:47
-
-
Save hamidrezayazdani/4fb2fc75759b04884fd8367777d035e8 to your computer and use it in GitHub Desktop.
کد کوتاه نمایش محصولات بر اساس تاریخ آخرین ویرایش در ووکامرس
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ywp_date_modified_wc_product_shortcode( $args, $atts ){ | |
$atts = shortcode_atts( | |
array( | |
'orderby' => 'date', | |
'interval' => '20', | |
), $atts, 'bartag' | |
); | |
if ( 'date_modified' === esc_attr( $atts['orderby'] ) ) { | |
$args['date_query'] = array( | |
array( | |
'column' => 'post_modified', | |
'after' => (int) $atts['interval'] . ' days ago', | |
'inclusive' => true, | |
), | |
); | |
} | |
return $args; | |
} | |
add_filter( 'woocommerce_shortcode_products_query', 'ywp_date_modified_wc_product_shortcode', 10, 2 ); | |
// The code goes to functions.php file of your active theme (or child theme) | |
// How to use? Like this: [products orderby="date_modified" interval="15"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment