Order search results by category

I stumbled over this looking myself for a solution to order posts from WP_Query by their related terms, which seems to be the quintessence of this question. (I’ll answer to the special search case of the question below the general description.) Sorting Posts by related Terms So the key is the MySQL function FIELD() which … Read more

Search Form Based On Tutorial Not Working

Crystal Ball Programming and Why Your Searchbox Failed Your form fails because of this: action=”<?php bloginfo(‘template_url’); ?>/MilkNHny/search.php” You should never directly call a template via URL. Your template assume the WordPress environment has been loaded, which is a fair assumption. However, because you called it directly, it has not. Search.php is the template WordPress looks … Read more

How to multiply a post to test internal search results?

Well, there are ways to duplicate posts, but I don’t think that’s what you need. Check out http://wordpress.org/plugins/bulk-content-creator/, which is probably exactly what you’re after, and allows you to create many posts at once for test purposes. Otherwise, check out http://codex.wordpress.org/Theme_Unit_Test where you can get test content.

custom autocomplete search

I found my problem. It was just a problem from my search php script! Without trim( $_REQUEST[‘term’] ) it will not correctly filter results. Now like this it works perfectly: function search_autocomplete(){ $posts = get_posts( array( ‘s’ => trim( $_REQUEST[‘term’] ), ‘post_type’ => array(‘post’, ‘portfolio’) ) ); $suggestions=array(); global $post; $args = array(‘post_type’ => array(‘post’, … Read more

Search – Only search for post meta field

I’m not quite sure this is what you want (because it is so … easy), but all you need to do is add the following inputs to your search form: <input type=”hidden” id=”meta_key” name=”meta_key” value=”YOUR-META-KEY”> <input type=”hidden” id=”meta_value” name=”meta_value” value=”YOUR-META-VALUE”> Or, if you want to trigger the search by hand, do it like so: $search … Read more

How to modify search.php to not show pages only show posts

The search template is way too late to change anything: The pages are searched already here, and your page numbers would be wrong. Do not alter the output, alter the query. Filter posts_search instead, and if there is a search term, filter posts_where_paged and remove the post type you don’t want to be searched. Sample … Read more

WordPress Custom Search Form Displaying Unexpected Results

You are likely getting unexpected results due to your query string. I would recommend getting familiar with the following: List of WordPress Query Variables WordPress function: get_query_var($var); List of WordPress Reserved Terms. Reserved Terms Avoiding the following reserved terms is particularly important if you are passing the term through the $_GET or $_POST array. Doing … Read more

Get a list of posts by specific category

You can also use the following query for getting the results if you have author_id, post_status and cat_id with you. global $wpdb; $author_id = 1; $cat_id = 1; $post_status=”publish”; /* Post Titles */ $search_titles = $wpdb->get_col( “SELECT DISTINCT post_title FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) … Read more