Modify search form with plugin

Here’s an alternative way to only make the product post type searchable, from a plugin code: <?php /** Plugin Name: Product Search Only **/ add_filter( ‘register_post_type_args’, function( $args, $post_type ) { $args[‘exclude_from_search’] = true; if( ‘product’ === $post_type && (bool) $args[‘public’] ) $args[‘exclude_from_search’] = false; return $args; }, 999, 2 ); Here we modify the … Read more

making a search.php query

You are missing the search parameter in your arguments. The code below, when added to the array in $the_query, should pass along the query string variable from a search: ‘s’ => $s Documentation is available here: https://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter

Include images from pages in wp search.php results in default wp search

To include the attachment (media) post type in search results, use the following code snippet function attachment_search( $query ) { if ( $query->is_search ) { $query->set( ‘post_type’, array( ‘post’, ‘attachment’ ) ); $query->set( ‘post_status’, array( ‘publish’, ‘inherit’ ) ); } return $query; } add_filter( ‘pre_get_posts’, ‘attachment_search’ ); Source However, this does not take care of … Read more

Search custom post type result in same template page

1.Create a single-(cpt).php in your theme, duplicate a your single.php and rename it as per your CPT name, so this page template will use to show your CPT queries. For more details refer the wordpress codex. https://codex.wordpress.org/Category_Templates To create CPT arcive page follow the same proceduare. archive-(cpt).php For Taxonimies taxonomy-(cpt).php CPT is your custom post … Read more

Highlight search words in excerpt

Use str_replace to replace all occurances of the word to highlight with a around the word. Something like // $searchresult = result of search process, //$highlightword = word you want to highlight $searchresult = str_replace( $highlightword, “<span style=”background-color:#ffff00;”>$highlightword</span>”, $searchresult ); Adjust the background-color to what you want to use. To limit the number of words … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)