Building a search box with taxonomies and custom fields
Building a search box with taxonomies and custom fields
Building a search box with taxonomies and custom fields
You can use the meta_query parameter of WP_Query to search custom fields. Untested: $meta_query = $query->get( ‘meta_query’, array() ); $meta_query[] = array( ‘key’ => ‘function_name’, ‘value’ => $query->query_vars[‘s’], ‘compare’ => ‘LIKE’, ); $query->set( ‘meta_query’, $meta_query );
Did you add your cpt to the search query ? function include_cpt_in_search($query) { if (is_admin() || !$query->is_main_query()) return; if ($query->is_search) { $query->set(‘post_type’, array(‘post’, ‘page’, ‘your_custom_post_type’)); } } add_action(‘pre_get_posts’, ‘include_cpt_in_search’);
Can you explain how did you put the search form? Are you working in code or with any page builders? Assuming you are using code, best case is to use Javascript / Ajax to search in the same page. Other options include submitting the search form and reloading the page with data. You can add … Read more
ajax select parent show child in another select and show posts in another select-ajax filter search
Search Filter by mime type not working in pre_get_posts
This is because elseif doesn’t work the way you think it does. You’re trying to use it in a way that’s closer to a switch statement or multiple if statement` This: if (post_type_exists(‘videos’)) { // exclude from search results $wp_post_types[‘videos’]->exclude_from_search = true; } elseif (post_type_exists(‘coordinator’)) { // exclude from search results $wp_post_types[‘coordinator’]->exclude_from_search = true; } … Read more
Search results not finding in paginated pages just in visible rows
If you have registered a custom post type and have added a custom template for it to your theme, then you could do something like this. Add a helper function to functions.php that creates a custom query to find posts matching the topic slug. Using a helper keeps the template file a little cleaner. // … Read more
you’re using $query->set(‘post_type’, ‘post’); to only include posts. What you can do is make it an array to include the post type and those specific page IDs you want. Here’s an example code: function custom_search_filter($query) { if ($query->is_search() && !is_admin() && $query->is_main_query()) { $query->set(‘post_type’, ‘post’); // Add the IDs of the pages you want to … Read more