Skip to content

Instantly share code, notes, and snippets.

@luanpiegas
Last active July 21, 2016 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luanpiegas/51560598cbee58e6881531ee003feab0 to your computer and use it in GitHub Desktop.
Save luanpiegas/51560598cbee58e6881531ee003feab0 to your computer and use it in GitHub Desktop.
Snippet para shortcode do Wordpress
<?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