How to rewrite wordpress search to work on specific category

You can use add_rewrite_rule(): add_action( ‘init’, function(){ // Non-paged requests. E.g. example.com/categoryname/search/keyword/ add_rewrite_rule( ‘^categoryname/search/([^/]+)/?$’, ‘index.php?category=categoryname&s=$matches[1]’, ‘top’ ); // For paged requests. E.g. example.com/categoryname/search/keyword/page/2/ add_rewrite_rule( ‘^categoryname/search/([^/]+)/page/(\d+)/?$’, ‘index.php?category=categoryname&s=$matches[1]&paged=$matches[2]’, ‘top’ ); } ); Be sure to flush the permalinks — simply visit the Permalink Settings page.

Woocommerce Backend Search by Title and SKU

Please try this code function search_by_sku( $search, &$query_vars ) { global $wpdb, $pagenow; if ( ‘edit.php’ != $pagenow || ! is_search() || ! isset( $query_vars ->query_vars[‘s’] ) || ‘product’ != $query_vars ->query_vars[‘post_type’] ) { return $search; } if(isset($query_vars->query[‘s’]) && !empty($query_vars->query[‘s’])){ $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => … Read more

Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?

You can limit a search to a particular post-type quite easily: https://www.wpbeginner.com/wp-tutorials/how-to-limit-search-results-for-specific-post-types-in-wordpress/ Or a nice simple way to limit a search to a particular category by adding a hidden field into the search form: https://www.wpexplorer.com/limit-wordpress-search/ In terms of post vs page for custom post types, you can find the differences on the documentation page for … Read more

How do I exclude a specific page (and child pages) from the search results?

// Filter to exclude a page and it’s child pages from search query function myfilter_exclude_pages_from_search( $query ) { // Save the post id of the page to be excluded in $parent_post_id_to_exclude $parent_post_id_to_exclude = 111; // Replace 111 with actual page id // Convert the post id to an array $parent_post_id_arr = array( $parent_post_id_to_exclude ); // … Read more

See if a post has a specified tag

You should wrap your condition with brackets according to PHP syntax: if (has_tag(‘Cat’, $post_id)) { $taganimal = “Cat”; } If you need to check multiple tags you can use something like foreach ([‘Cat’, ‘Dog’] as $animal) if (has_tag($animal, $post_id)) { $taganimal = $animal; break; } but it would find only the first tag listed in … Read more