Last active
August 7, 2017 19:20
-
-
Save deryckoe/432af4c69be1fd5fc7e64f8df6f9d684 to your computer and use it in GitHub Desktop.
Modificar los resultados de búsqueda en WordPressModificar los resultados de búsqueda en WordPress
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 create_movie_cp() { | |
register_post_type( 'movies', | |
// Opciones del custom post | |
array( | |
'labels' => array( | |
'name' => __( 'Movies' ), | |
'singular_name' => __( 'Movie' ) | |
), | |
'public' => true, | |
'exclude_from_search' => false, | |
'rewrite' => array( | |
'slug' => 'movies' | |
) | |
) ); | |
} | |
add_action( 'init', 'create_movie_cp' ); |
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 search_filter($query) { | |
// Si la query es de busqueda... | |
if ($query->is_search) { | |
// ...establece la cantidad de resultados por pagina | |
$posts_per_page = get_option('posts_per_page') * 2; | |
$query->set('posts_per_page', $posts_per_page ); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','search_filter'); |
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 search_filter($query) { | |
// Si la query es de busqueda... | |
if ($query->is_search) { | |
// ...establece el tipo de contenido como movies | |
$query->set('post_type', 'movies' ); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','search_filter'); |
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 search_filter($query) { | |
// Si la query es de busqueda... | |
if ($query->is_search) { | |
// ...establece el tipo de contenido como post (entrada) solamente | |
$query->set('post_type', 'post'); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','search_filter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment