Created
December 2, 2015 09:47
-
-
Save Aziz-Rahman/7e81397eef3765d0ce62 to your computer and use it in GitHub Desktop.
Rewrite url search wp
This file contains hidden or 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 | |
/** | |
* Search rewrite url -> save this in function.php | |
* | |
* @package WordPress | |
* @subpackage Imagefinder | |
* @since Imagefinder 1.0.0 | |
*/ | |
if ( !function_exists( 'warrior_search_url_rewrite ') ) { | |
function warrior_search_url_rewrite() { | |
if ( is_search() && ! empty( $_GET['s'] ) ) { | |
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); | |
exit(); | |
} | |
} | |
} | |
add_action( 'template_redirect', 'warrior_search_url_rewrite' ); | |
?> |
This file contains hidden or 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 | |
/** | |
* The template for displaying posts in the search results. | |
* | |
* @package WordPress | |
* @subpackage Imagefinder | |
* @since Imagefinder 1.0.0 | |
*/ | |
get_header(); | |
global $query_string; | |
$get_search_result = get_query_var( 's' ); // get url modivications in functions.php | |
?> | |
<div id="item-list" class="row"> | |
<?php | |
// The loop search | |
$search['post_type'] = 'photo'; | |
$search['s'] = $get_search_result; | |
query_posts( $search ); | |
if ( have_posts() && !empty( $get_search_result ) ) : | |
while ( have_posts() ) : | |
the_post(); ?> | |
<div class="col-lg-4 col-md-4 col-sm-4 gallery-img"> | |
<div class="inner"> | |
<div class="gallery-overlay"> | |
<div class="overlay-content"> | |
<a href="<?php the_permalink(); ?>"><?php _e( 'View Image', 'imagefinder' ); ?></a> | |
</div> | |
</div> | |
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'post-thumbnail' ); ?></a> | |
</div> | |
</div> | |
<?php endwhile; | |
else : | |
_e( 'Sorry, no listings matched your criteria, please try again for valid keywords.', 'imagefinder' ); | |
endif; | |
get_template_part( 'includes/pagination' ); // include pagination | |
echo $get_search_result; | |
?> | |
<span class="label"><?php the_tags( __( '<b>Tags:</b> ', 'imagefinder' ) , ', ', '' ); ?></span> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment