Search for posts based on their url in the admin?

Here’s one way to support searching for post slugs in the backend. Let’s invoke this kind of search by the slug: string in the search term. Example To search for slugs that end in -2 we want to be able to search for: slug:*-2 where * is the wildcard. Demo Plugin Here’s a demo plugin … Read more

is_search was called incorrectly

The Why part In the core is_search() function there’s a check if the global $wp_query is set: global $wp_query; if ( ! isset( $wp_query ) ) { _doing_it_wrong( __FUNCTION__, __( ‘Conditional query tags do not work before the query is run. Before then, they always return false.’ ), ‘3.1.0’ ); return false; } Note that … Read more

Change query variable for wordpress search

The code you found works not by changing the query variable but by converting another variable into the s variable that WordPress expects. If you look at the WP_Query object, that s parameter is pretty deeply embedded into Core functionality. The simple solution, and perhaps the only one, is to choose some other parameter for … Read more

disable admin-bar search field for specific roles

Just in case anyone trips over this…here’s how you remove “search” and some examples of other things you can remove from the admin bar: public function remove_admin_menu_bar_items ($wp_toolbar) { $wp_toolbar->remove_node( ‘my-sites’ ); $wp_toolbar->remove_node( ‘wp-logo’ ); $wp_toolbar->remove_node( ‘new-content’ ); $wp_toolbar->remove_node( ‘view’ ); $wp_toolbar->remove_node( ‘logout’ ); //remove “logout” under “howdy” $wp_toolbar->remove_node( ‘user-info’ ); //remove “youraccount” under “howdy” … Read more

Advanced Search by minimum/maximum values

A meta_query is an array of arrays. You only have an array. $query->set(‘meta_query’, array( ‘key’ => ‘shru_price’, ‘value’ => $_GET[‘minPrice’], ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ )); It should be: $query->set( ‘meta_query’, array( array( ‘key’ => ‘shru_price’, ‘value’ => $_GET[‘minPrice’], ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’ ) ) ); And please validate/sanitize that user supplied … Read more

Comparing between a negative and positive number

I tried the following code: $posts = get_posts([ “post_type” => “CUSTOM_POST_TYPE”, “meta_query” => [ ‘relation’ => ‘AND’, [ ‘key’ => ‘longitude’, ‘value’ => [-0.9895, 1.3125], ‘compare’ => ‘BETWEEN’, “type” => “NUMERIC”, ], ], ]); When I remove “type” => “NUMERIC”, I could reproduced your problem because the comparison is string based. But when adding the … Read more

Change loop.php for empty search customization

I feel bad for answering my own question on here, but here’s what I did. I created a custom search template, a custom searchform.php and changed my header.php to reflect my custom search page. What I did is rename the search box names to search instead of s to get around WordPress automatically running search.php … Read more