How to make a WP_Query search with custom post types?
You are right, I tried it in a clean WordPress install and it works. Seems like one of the plugins I use in my environment is hooking itself in one of the pre-query events. Thanks!
You are right, I tried it in a clean WordPress install and it works. Seems like one of the plugins I use in my environment is hooking itself in one of the pre-query events. Thanks!
The simplest option if you want to show search results within a page context you’ll need to do a custom loop, otherwise you won’t be able to access the page information. Change the input with the name s to something else like search or q to stop wordpress from doing it’s usual built in search. … Read more
It is possible, but you’ll have to play a little bit with the actual query. As always, the furious posts_clauses filter comes to action: function wpse_alter_posts_search( $pieces ) { global $wpdb; // Make the input save $search_string = like_escape( $_GET[‘s’] ); // Your new WHERE clause $where = $wpdb->prepare( “$wpdb->postmeta.%s LIKE %s”, ‘YOUR_COLUMN’, // Should … Read more
I’m using this code in my search.php above the main loop: $search_term = explode( ‘ ‘, get_search_query( false ) ); global $wpdb; $select = ” SELECT DISTINCT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN (‘category’)”; $first = true; foreach ( $search_term as $s ){ … Read more
Instead of ‘cat’ => 12 and $wp_query use ‘category_name’ => slug and get_posts(). Here is a basic example how it works: PHP add_action( ‘wp_loaded’, array ( ‘T5_Ajax_Search’, ‘init’ ) ); /** * Ajaxify the search form. */ class T5_Ajax_Search { /** * The main instance. You can create further instances for unit tests. * @type … Read more
Add this snippet to your functions.php function redirect_the_single_post() { if (is_search() && is_main_query()) { global $wp_query; if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) { wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) ); exit; } } } add_action(‘template_redirect’, ‘redirect_the_single_post’ ); hope this will help you!!
If the search field is implemented as a widget, this can be done via the administration interface. Just navigate to Appearance > Widgets and drag the search widget from the widget area to the “Available Widgets” pane. If the search field is hard-coded into the theme, it might be easier to edit the CSS rather … Read more
I came up with a solution for your first question. i.e the tax metabox that only suggests terms from existing terms list but does not allow you to add new terms. The solution is jQuery based and modifies the default behavior of the tags (i.e non heirarchical taxonomies) meta box. Limitation: Currently it only allows … Read more
You can’t achieve this easily with WP’s built-in search system. Even if you managed to build a complicated query that pulls data from the user table, it would be incredibly slow. Search Unleashed had this functionality, but I’m not sure about compatibility with WP 3.2. I used it in the past as inspiration to add … Read more
Good news and more good news! First – all of the code related to WordPress itself and its repositories resides in version control system (Subversion). Among other things that makes publicly available sites with all code in plain sight: http://core.svn.wordpress.org/ http://themes.svn.wordpress.org/ http://plugins.svn.wordpress.org/ One not so obvious result of that – if you can see it, … Read more