Last active
March 1, 2016 08:30
-
-
Save avillegasn/ac6a8d91f2fb02739267 to your computer and use it in GitHub Desktop.
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 wprin_buscador_shortcode( $atts, $content=null ) { | |
ob_start(); | |
extract( shortcode_atts( array( 'nombre' => '' ), $atts ) ); | |
$string = $atts['nombre']; | |
$args = array( 's' => $string ); | |
$the_query = new WP_Query( $args ); | |
if ( $the_query->have_posts() ) { | |
echo '<ul>'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); ?> | |
<li> | |
<a href="<?php the_permalink() ?>"> | |
<?php the_title(); ?> | |
</a> | |
</li> | |
<?php | |
} | |
echo '</ul>'; | |
} else { | |
echo "No se han encontrado entradas"; | |
} | |
wp_reset_postdata(); | |
return ob_get_clean(); | |
} | |
add_shortcode( 'wprinbuscador', 'wprin_buscador_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment