Tag Info

Hot answers tagged

4

You need to place the following code in your theme's search.php file. <?php $search_query = get_search_query(); if ( $search_query == 'gold' ) { echo 'my gold ad'; } else if ( $search_query == 'oil' ) { echo 'my oil ad'; }


3

You can get close to what you want by using the template_redirect hook. function my_custom_search_url_rewrite() { if ( is_search() && ! empty( $_GET['s'] ) ) { wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) ); exit(); } } add_action( 'template_redirect', 'my_custom_search_url_rewrite' ); Then you can use a URL ...


2

I think it is better that you switch to the current beta, version 2, publish on github. This version is much better in possibilities and performance. In this version it is possible that you get a result for the search term, Iike GET /wp-json/wp/v2/posts?s=awesome.


2

You need a meta_query something like this: $args = array( 'post_type' => 'shop', 'meta_query' => array( array( 'key' => 'map-location', 'value' => 'London', 'compare' => 'LIKE' // the = operator might work depending on how your data is stored ), ) ); Note: I am making some ...


1

You could use regular expression RLIKE: $val = '15'; $args = array( 'post_type' => 'shop', 'meta_query' => array( array( 'key' => 'map-location', 'value' => 's:7:"address";s:[0-9]+:"[^"]*' . preg_quote( $val ) . '[^"]*";', 'compare' => 'RLIKE' ), ) ); although it can fail if ...


1

This type of ordering is not available by default. You however have two basic options here rewind_posts() -> Rerun the loop multiple times and use rewind_posts() to rewind the loop so you can rerun it again EXAMPLE if ( have_posts() ) { while( have_posts() ) { the_post(); if ( $post->post_type == 'books' ) { // Output ...


1

Just extend your search form with a hidden input: (notice the last input field) <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span> <input type="search" ...


1

You need to use the user_search_columns filter to add the columns you want to search on. The user_search_columns filter is used to determine which user fields in the database are used when performing a search on user information. https://codex.wordpress.org/Plugin_API/Filter_Reference/user_search_columns


1

jpd527, Please remember that 'tag' is singular and not plural. Here your form has multiple HTML element with same id so this is wrong. Now if you require to search data with two different inputs, then you can merge it via JS. HTML code like: <form method="get" id="search form" action="/"> <div> <input type="text" value="" name="tag_one" ...



Only top voted, non community-wiki answers of a minimum length are eligible