Unexpected esc_html and esc_attr behaviour
Use get_search_query or the_search_query to return/output the search term as a properly escaped value, don’t access $_GET directly. You’re trying to escape something that’s already URLencoded.
Use get_search_query or the_search_query to return/output the search term as a properly escaped value, don’t access $_GET directly. You’re trying to escape something that’s already URLencoded.
If you’re using FontAwesome, you can display an icon in the placeholder text like this : HTML <input placeholder=”” class=”fontAwesome”> CSS .fontAwesome{ font-family: ‘Helvetica’, FontAwesome, sans-serif; }
You can query a list of post IDs using $wpdb based on their slugs, and then use that in your filter. Here’s a simple example of how to do this: function mm_search_filter( $query ) { // We will query a list of post IDs // by using $wpdb global $wpdb; $post_ids = $wpdb->get_results(“SELECT ID FROM … Read more
In PHP, the number 0 is interpreted as false-ish. Your if-statement asks for a true-ish condition like this: If the result of the array_search function is interpreted as true-ish, THEN do the stuff which means if the result is 0, it is interpreted as false, and the code doesn’t run. What to do? Use the … Read more
This question is too broad to answer in detail, but here is how I would approach this: Given that WP’s native search is slow, we can rule out using this to get intermediate results while the visitor is typing. Unless we have a lightning fast dedicated server. So, this means we will have to build … Read more
I’m not entirely sure, but it seems like you want to store the last visited page for future use (a go back button?). I see two ways to do this: Keep it in the URL as a get argument the same way you save the search queries. This leads to a long url, though Save … Read more
get_search_query() returns only the string that the user searched for. To display the search results, you’ll need to do some more work. The search results will be in $wp_query, and you can manipulate it using The Loop (like any other page). The following code is adapted from WordPress’s own Twenty Twenty theme‘s index.php file, and … Read more
I’ve found that passing post_type doesn’t restrict searches to that type, but just adds that type to the array it already searches. What you can do to build complex search queries is hook pre_get_posts and do a little query manipulation. For a simple example, first I add my own query var to pass to WordPress’s … Read more
A colleague of mine gave me this helpful answer, I hope it helps others: “To answer definitively, I would need to see a bit more code. Nonetheless, WordPress does override $_REQUEST, so depending on where this code is placed, it may be overwritten. So assuming that the parameter is being passed in the URL, I … Read more
WordPress searches the columns post_title and post_content. If you add your content to these columns they are searched. If you add the extra content per filter or shortcode during output you need a search plugin that is capable of indexing rendered pages (Relevanssi or Search Everything for example).