Coby!! Posted August 24, 2012 Report Share Posted August 24, 2012 Estimados, estoy tratando que el buscador de mi pagina (wordpress) solo realice sus búsquedas por el titulo de las entradas y no por el contenido de las mismas. Actualmente mi functions.php luce así: <?phpif ( function_exists('register_sidebar') ) register_sidebars(2, array( 'before_widget' => '<li><div id="%1$s" class="%2$s">', 'after_widget' => '</div></li>', 'before_title' => '<h3>', 'after_title' => '</h3>' ));function widget_mytheme_search() {?> <li><div> <form method="get" action="<?php bloginfo('home'); ?>"> <input type="text" name="s" id="s" size="35" /> <input class="searchbutton" type="submit" value="<?php _e('Search'); ?>" /></form> </div></li><?php}if ( function_exists('register_sidebar_widget') ) register_sidebar_widget(__('Search'), 'widget_mytheme_search'); ?> Pero encontré en una pagina el código para añadirle la función (filtro) que necesito. La cual sería la siguiente: add_filter('posts_search', 'mi_search_title');function mi_search_title($search) { preg_match('/%([^%]+)%/', $search, $m); if (isset($m[1])) { // Original // " AND (((wp_posts.post_title LIKE '%termino%') OR (wp_posts.post_content LIKE '%termino%'))) AND (wp_posts.post_password = '') " return " AND wp_posts.post_title LIKE '%$m[1]%' AND (wp_posts.post_password = '') "; } else { return $search; }}Le traté de agregar el codigo pero algo hice mal y al tratar de logear en la pagina me aparecía el siguiente error: Warning: Cannot modify header information (el cual finalmente pude arreglar restaurando functions.php via ftp). La consulta, como debería quedar el código con el filtro añadido?. Gracias de antemano, Saludos. Link to comment Share on other sites More sharing options...
AshWilliams Posted August 24, 2012 Report Share Posted August 24, 2012 En <?php bloginfo('home'); ?> ahi creo que debe estar la función que realiza el filtrado.....y ahi debe ser donde tengas que reemplazar el código :) PS: Saludos :krider: Link to comment Share on other sites More sharing options...
cañangasñangas Posted December 13, 2012 Report Share Posted December 13, 2012 movido a webmaster Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now