wp_query ‘s’ parameter does not work with custom post type

You can do like this, $args = array( ‘post_type’ => ‘tribe_events’, ‘post_per_page’ => get_option(‘posts_per_page’), ‘s’ => get_search_query() ); $query = new WP_Query($args); // Use new keyword and you need to use WP_Query not Wp_Query while($query->have_posts()): $query->the_post(); the_title(); endwhile;wp_reset_postdata(); I used this in search.php file. Worked without any problem.

Any reason why search result lists only one entry?

What template does search page use? It is either generic index.php or specialized search.php. What does Loop in that template look like? I suspect this might be Loop issue that is set to only dislpay single post, instead of iterating all of them.

Search Results: Differentiate posts and pages

<?php if(get_post_type() == ‘page’): // Only pages ?> <div class=”recent_postMetaSingle”> <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/eye.png” alt=”Views” title=”views” /> <?php print_page_views(get_the_ID(”)); ?> <p>This is a static page!</p></div> <?php elseif(get_post_type() == ‘post’): // If not page, Only posts ?> <div class=”recent_postMetaSingle”> <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/eye.png” alt=”Views” title=”views” /> <?php print_page_views(get_the_ID(”)); ?> &nbsp;&nbsp;&nbsp; <img src=”https://wordpress.stackexchange.com/questions/31727/<?php bloginfo(“template_directory’); ?>/images/comments2.png” alt=”Comments” title=”comments” … Read more

Keyword search limited to specific post type filtered by multiple custom taxonomies?

It’s fairly inefficient to use query_posts and I often find it’s more trouble than it’s worth. Instead, to set the post type you can just have a hidden input inside the form with name ‘post_type’ and value (in this example) ‘news’. WordPress handles the rest. Unfortunately it is not so easy with taxonomies (maybe I’ve … Read more

Custom dashboard widget search box

The following will do, although it redirects to the Posts listing page /wp-admin/edit.php… Also included, search boxes for Pages and CPTs. Code /** * PLEASE NOTE THAT THE FOLLOWING CODE DOESN’T HAVE ANY SANITIZATION or NONCE methods */ add_action(‘wp_dashboard_setup’, ‘wpse_58520_dashboard_search_widget’); function wpse_58520_dashboard_search_widget() { wp_add_dashboard_widget( ‘wpse_54742_active_site_plugins’, __( ‘Search Posts/Pages/CPTs’ ), ‘wpse_58520_make_dashboard_search_widget’ ); } function wpse_58520_make_dashboard_search_widget() { … Read more

Add relevant tag to search results

In functions.php: function wpse82525_link_search_to_tag() { // check if search archive is being displayed if( ! is_search() ) return; // get search query var $sqv = get_query_var( ‘s’ ); // get tag base $tagbase = get_option( ‘permalink_structure’ ) ? get_option( ‘tag_base’ ) ? trailingslashit( get_option( ‘tag_base’ ) ) : ‘tag/’ : ‘?tag=’; // return link if … Read more