Last active
July 21, 2016 18:26
-
-
Save luanpiegas/51560598cbee58e6881531ee003feab0 to your computer and use it in GitHub Desktop.
Snippet para shortcode do Wordpress
This file contains 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 shortcode_mostra_produtos ( $atts ) { | |
$atts = shortcode_atts( array( | |
'default' => '' | |
), $atts ); | |
$terms = get_terms('linhas'); | |
wp_reset_query(); | |
$args = array('post_type' => 'produtos', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'linhas', | |
'field' => 'slug', | |
'terms' => $atts, | |
), | |
), | |
); | |
$loop = new WP_Query($args); | |
if($loop->have_posts()) { | |
while($loop->have_posts()) : $loop->the_post(); | |
echo ' "'.get_the_title().'" '; | |
endwhile; | |
} | |
} | |
add_shortcode( 'produtos','shortcode_mostra_produtos' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment