Skip to content

Instantly share code, notes, and snippets.

@camilolunacom
Last active August 28, 2019 01:21
Show Gist options
  • Save camilolunacom/76a1040d95d7fc9de947386376a9f838 to your computer and use it in GitHub Desktop.
Save camilolunacom/76a1040d95d7fc9de947386376a9f838 to your computer and use it in GitHub Desktop.
<?php
function productos_nuevos_shortcode() {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'meta_key' => 'nuevo',
'meta_value' => '1'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
echo '<div class="woocommerce columns-4"><ul class="products columns-4">';
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
echo '</ul></div>';
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
}
add_shortcode('productos_nuevos', 'productos_nuevos_shortcode');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment