How to extend WP_query to a specific table?
How to extend WP_query to a specific table?
How to extend WP_query to a specific table?
$name=”John Doe”; // Split $name $name = preg_split( ‘/\s+/’, trim( $name ) ); // Set first name $first_name = $name[0]; // Last name was provided? $last_name = isset( $name[1] ) ? $name[1] : null; // Define meta query args array $meta_query_args = array(); // Set “first name” meta query or “first name” + “last name” … Read more
Here is one to create a search form with tag and category filters. For filtering posts this form uses the default text input way, where user can type some search phrase that is matched against post titles and content. 1) Added to theme’s functions.php function get_tag_ids_and_names() { $out = array(); $arga = array( // check … Read more
This code will only search form woocommerce products. If you want to show any other search result from another post type you can do by simply change post type slug ‘product’ with you own post type slug add_action( ‘pre_get_posts’, ‘wpse223576_search_woocommerce_only’ ); function wpse223576_search_woocommerce_only( $query ) { if( ! is_admin() && is_search() && $query->is_main_query() ) { … Read more
Solved by a dropdown – <h1 class=”titlebar”><div id=”sortby”> SORT BY:; Sort by Newest Oldest Most Viewed Relevance Duration
Modify main search form to search user too
Replacing + sign to – in wp Search Permalink
Your code says, “If the search term isn’t empty, and that exact search term is in my search replacements array, then replace the term.” So, instead of this: !empty($search_replacements[$request_vars[‘s’]] (which means, if this exact search term [$request_vars[‘s’] is in my $search_replacements array) you’ll need to instead loop through your search replacements array every time someone … Read more
First verify your product attribute (meta_key) by running this query Note: Change table prefix according to your wordpress database mine is default wp_ SELECT * FROM wp_postmeta WHERE meta_key LIKE ‘%code%’; /* get attribute name example (_sku, _stock, _stock_status, height, width )*/ Now add this to your functions.php file function Add_custom_search( $query ) { if( … Read more
First you want to make the query keys available so you can check them later: add_action( ‘init’, ‘custom_add_query_vars’ ); function custom_add_query_vars() { add_query_var( ‘location’ ); add_query_var( ‘tag’ ); } Then you want to set a tax_query by filtering the WP Query: add_filter( ‘pre_get_posts’, ‘custom_search_tax_query’ ); function custom_search_tax_query() { // check this is a search query … Read more