Custom search for custom post type, custom meta and search fields

If you want to extend your query, you should extend it through the pre_get_posts-filter. Then just do a “Custom Field” or meta query. add_action( ‘pre_get_posts’, ‘wpse105969_extended_search’ ); function wpse105969_extended_search( $query ) { // Make sure we got a search query // and we’re only modifying the main query. if ( ! $query->is_main_query() AND ” === … Read more

How to get posts by content?

You have to extend the db query to search in the post_content column. There is a filter: ‘posts_where’ you can use. I would write a simple wrapper for get_posts() to extends its arguments an run the filter once. Example: class T5_Posts_By_Content { protected static $content=””; protected static $like = TRUE; /** * Mapper for get_posts() … Read more

How to create a WP_Query to search the Title or Tag?

Please use below code to show posts in texonomy and titles $s = $request[‘s’]; $tags = str_replace(‘ ‘, ‘-‘, strtolower($request[‘s’])); $q1 = get_posts(array( ‘fields’ => ‘id’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘s’ => $s )); $q2 = get_posts(array( ‘fields’ => ‘ids’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tag’ … Read more

searching in custom meta field

After thinking about the problem, I found the simplest solution, do a direct query using $wpdb in archive-{post-type}.php <?php global $wpdb; $meta_key = get_query_var(‘publisher’); $result = $wpdb->get_results(” SELECT * FROM ” . $wpdb->prefix. “postmeta_books WHERE publisher LIKE ‘%$meta_key%’ “); foreach( $result as $results ) { echo $results->publisher; echo ‘<br/>’; } ?> It is the basic … Read more

Sort posts by number of matched terms

Well the only way i can think of is to create an two dimentions array of the results you want to output, and the number of matching tags. so for example: $results = array(); $searched_tags = $_post[‘my_tax’]; $searched_tags = explode(“+”, $searched_tags); while (have_posts()){ $the_post(); $result[‘r’] = ‘<div class=”post”> <div class=”title”><h2><a href=”‘.get_permalink($post->ID).'” title=”‘.get_the_title($post->ID).'”>’.get_the_title($post->ID).'</a></h2></div> <div class=”excerpt”>’.get_the_excerpt().'</div> </div>’; … Read more

Fulltext search in posts sorted by relevancy

You may want to check the Sphinx search engine http://sphinxsearch.com/ It took me about one day to set it up and learn how to use, but it does really good job with sorting by relevancy and grammar stemming. Also it is faster than fulltext search for big data sets thanks to indexing.

Is there a way to do multiple ordering on a multiple meta_query?

As of WordPress 3.4.1, there is no way, out of the box, to order by multiple meta values. Since we can’t do it cleanly, we’ll have to hack something together. We can hook into posts_orderby to manually modify the ordering. It’s not altogether pretty, but it will get the job done. Here’s an example: add_filter(‘posts_orderby’, … Read more

dynamic page not indexed

Do you have at least have a link to the query url somewhere on your public pages ? Google does follow query parameters, so that will at least bring it to the crawlers attention. See http://googlewebmastercentral.blogspot.com.au/2011/07/improved-handling-of-urls-with.html (I almost have the opposite with my event/calendar plugin. google is paying almost too much attention to the pages … Read more

BP Multi Network & Members Directory [closed]

You can filter the members loop in BuddyPress by meta values for the members. So you would need to change the loop in the template file members/members-loop.php to be: <?php // Getting current blog_id global $wpdb, $current_blog; $id = $current_blog->blog_id; // Setting variable for current blog_prefix $blog_prefix = $wpdb->get_blog_prefix( $id ); // Start the BuddyPress … Read more