How to have search results page sorted by post date

WordPress will order search results by newest post first by default, so if your results are in a different order then it looks like another plugin is affecting them. Have you tried searching with all other plugins disabled? If you’re using Relevanssi, then it won’t order results by date as Relvanssia overrides this with its … Read more

Custom post_type search pages

How are you restricting the search to your custom post type? If you are doing it by passing an additional argument, i.e. &type=myCustomPostType, you could use a conditional test, like: if(isset($_GET[‘type’] && $_GET[‘type’] == ‘myCustomPostType’)): get_template_part(‘loop’,’youtube’); else: get_template_part(loop); endif;

What does wordpress search, search?

yes, WordPress search only searches title or post content. There are a few plugins that extend search to taxonomies, Relevanssi is one. EDIT – The query WordPress produces for default search: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE ‘%test%’) OR (wp_posts.post_content LIKE ‘%test%’))) AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’) AND (wp_posts.post_status=”publish” OR … Read more

query_posts() – problem with “s” parameter

You shouldn’t use $_GET[‘s’] directly like that, and you definitely shouldn’t use query_posts, although I understand using it for testing. If you’re going to build your own search mechanism in this way, then you should run $_GET[‘s’]through the urldecode() function first, to make sure it doesn’t contain weird data that you might not expect and … Read more

Search WooCommerce Products in WordPress

Just extend your search form with a hidden input: (notice the last input field) <form role=”search” method=”get” class=”search-form” action=”<?php echo home_url( “https://wordpress.stackexchange.com/” ); ?>”> <label> <span class=”screen-reader-text”><?php echo _x( ‘Search for:’, ‘label’ ) ?></span> <input type=”search” class=”search-field” placeholder=”<?php echo esc_attr_x( ‘Search …’, ‘placeholder’ ) ?>” value=”<?php echo get_search_query() ?>” name=”s” title=”<?php echo esc_attr_x( ‘Search for:’, … Read more

Modify Search Query if original Query gave no results

You should create a custom query inside if. if ( $total_results == 0 ) { // Create a new query with the terms ‘Find Us’ $query = new Wp_query(‘s=Find Us’); if ($query->have_posts()): while ($query->have_posts()):$query->the_post(); //whatever you want to do with the result endwhile; endif; wp_reset_postdata(); } You can refer Creating a search page and Wp_query … Read more

Search posts missing a particular custom field

Try using ‘NOT EXISTS’ instead of ‘NOT LIKE’ and remove the value ( it’ll be removed by WP with NOT EXISTS ): $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘meta_query’ => array( array( ‘key’ => ‘verified’, ‘compare’ => ‘NOT EXISTS’ ) ) ); $query = new WP_Query( $args ); http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters