Skip to content

Instantly share code, notes, and snippets.

@avillegasn
Last active March 1, 2016 08:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save avillegasn/ac6a8d91f2fb02739267 to your computer and use it in GitHub Desktop.
<?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