Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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