Adding Custom Fields to Search

1) I think that your solution is perfectly acceptable in terms of the “right way” – post meta is intended for searching. Doesn’t seem hacky to me. 2) What you should do is build the meta_query separately: $meta_query = array(); if( !empty( $_GET[‘price’] ) ) { $meta_query[] = array( ‘key’ => ‘_price’, ‘value’ => $_GET[‘price’] … Read more

Can I use HTTP POSTs? Is there a better alternative?

WordPress is an HTTP/PHP web application. The ordinary rules of HTTP and PHP apply, and work. WordPress itself uses $_POST and $_GET more times than I can count. If you want to pass information from one page to another– say from a form to a search handler– you have to use one or the other. … Read more

How to search map address in custom post type?

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 assumptions about how ACF stores data.

Modifying the Search Results

add_filter( ‘pre_get_posts’, ‘__filter_pre_get_posts’ ); function __filter_pre_get_posts( $query ) { // this is to detect a public search query if ( ! is_admin() && $query->is_search ) { // DO your magic here… } }

Searching for content post

Stright from WordPress reference: https://developer.wordpress.org/reference/hooks/posts_search/#user-contributed-notes You can search by post title only with: function __search_by_title_only( $search, $wp_query ) { global $wpdb; if(empty($search)) { return $search; // skip processing – no search term in query } $q = $wp_query->query_vars; $n = !empty($q[‘exact’]) ? ” : ‘%’; $search = $searchand = ”; foreach ((array)$q[‘search_terms’] as $term) { … Read more

How to disable WordPress Search from Url?

There’s a filter to remove this feature, which is known more commonly as autocorrecting the URL rather than “search” per se. Place this in your site-specific plugin or your custom/child theme’s functions.php file: remove_filter(‘template_redirect’, ‘redirect_canonical’); There is also an old plugin that does this. See https://www.bloggersignal.com/stop-wordpress-from-guessing-urls/ for details.

How to create an advanced filter search?

Try this: PHP add_action( ‘wp_ajax_my_adv_search’, ‘ajax_my_adv_search’ ); add_action( ‘wp_ajax_nopriv_my_adv_search’, ‘ajax_my_adv_search’ ); function ajax_my_adv_search() { if ( ! check_ajax_referer( ‘my-adv-search’, ‘q_nonce’, false ) ) { echo ‘session_expired’; wp_die(); } $post_type = isset( $_POST[‘q_post_type’] ) ? $_POST[‘q_post_type’] : ”; $taxonomy = isset( $_POST[‘q_taxonomy’] ) ? $_POST[‘q_taxonomy’] : []; $year = isset( $_POST[‘q_year’] ) ? $_POST[‘q_year’] : ”; … Read more

How to filter search results by post type?

By all rights it should work, here’s the same thing applied to my own site: tomjn.com/?s=talk&post_type=tomjn_talks vs tomjn.com/?s=talk . Something else is the problem Specifically, if you replace the main query with a query_posts call or a WP_Query, that query won’t take into account parameters passed via the URL unless explicitly passed through manually. Instead, … Read more