Altering search results to handle a post meta field not working in current WordPress

I got this working through the following combination of functions (credit to this post): function search_join_custom( $join ) { global $wpdb; if ( is_search() ) { $join .=’ LEFT JOIN ‘.$wpdb->postmeta. ‘ ON ‘. $wpdb->posts . ‘.ID = ‘ . $wpdb->postmeta . ‘.post_id ‘; } return $join; } add_filter(‘posts_join’, ‘search_join_custom’ ); function search_where_custom( $where ) … Read more

WordPress search with more input fields?

Sorry, it’s unclear to me what your goal is, if you could clarify your question more and additional information like what kind of options you’re trying to use (are they custom fields, are they categories, tags, or other taxonomies, or another characteristic like post author?) First, the select inputs should not have blank name values. … Read more

What are the available options for “Name” in WP search?

There are two name‘s: The name query variable The name attribute in an input tag The Query Variable name represents the post slug. For example, I have a blog post on my site: https://tomjn.com/2018/07/23/deployment-and-wordpress/ It has this post name: deployment-and-wordpress I can also visit this URL: https://tomjn.com/?name=deployment-and-wordpress I could also find it via WP_Query in … Read more

Form for search pages by meta datas

Take a look at https://developer.wordpress.org/reference/classes/wpdb/get_col/ On your result page, receive the query as follows <?php if(isset($_POST[‘name’]) || isset($_POST[’email’])){ $name=”%” . $wpdb->esc_like( $_POST[‘name’] ) . ‘%’; $email=”%” . $wpdb->esc_like( $_POST[’email’] ) . ‘%’; global $wpdb; $prepare = $wpdb->get_col( $wpdb->prepare( ” SELECT post_id FROM “.$wpdb->prefix.”postmeta AS M WHERE M.meta_value LIKE ‘%s’ OR M.meta_value LIKE ‘%s’ “, $name, … Read more

How to exclude specific post_type from default search?

If you want to exclude the “product” post type (= WooCommerce products) from all front-end searches on your site, you can use this code: function my_adjust_post_type_args( $args, $post_type ) { if ( ‘product’ === $post_type ) { $args[‘exclude_from_search’] = true; } return $args; } add_filter( ‘register_post_type_args’, ‘my_adjust_post_type_args’, 10, 2 ); It modifies the “exclude_from_search” argument … Read more

Redirect wordpress search query if its a tag

To do it in query handling stage, may use request hook which is when WordPress query is being setup. The term link is recommended by @Jacob Peattie using built-in get_term_link() instead of building it manually for more flexibility and error-proof. add_filter( ‘request’, ‘ws366006_check_request_query’ ); function ws366006_check_request_query( $query ) { // var_dump($query); // redirect checking if( … Read more

Search results – 404 error after hitting enter

It appears your search is going to https://youthtalkedinburgh.co.uk/?post_type[]=&s=sport instead of the (more proper) https://youthtalkedinburgh.co.uk/?s=sport, which works. Looking at the source, it appears your search form looks like this (simplified): <form … > <input type=”hidden” name=”post_type[]” value=””> <input name=”s”… > … </form> That <input type=”hidden” name=”post_type[]” value=””> input field doesn’t seem to belong. I suspect either … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)