Search Using Post ID

I previously asked and answered my own question about customizing a search. You can find that answer here: The right way to create a custom search page for complex custom post types. It’ll be a good read to help you understand the following code. I’ll use the pre_get_posts action to change your search when you … Read more

Disable Redirect to Product Page on Search Results Page in WooCommerce [closed]

Yes, this is totally possible. WooCommerce includes a handy filter that you can manipulate to disable that redirect so the user will continue onto the search results page as per normal. If you add this line of code to your functions.php file it will disable the redirect functionality. add_filter( ‘woocommerce_redirect_single_search_result’, ‘__return_false’ ); Permalink to gist: … Read more

Do I need to sanitize WordPress search query?

No. WordPress sanitizes the search query. To use the sanitized search query, use the_search_query() to echo, or get_search_query() to return, the search query. Edit Based on your edit: Don’t use $_GET[‘s’]. Use get_search_query(). Don’t use $_GET[‘cat’]. Use get_the_category(). All $_GET and $_POST data should be assumed to be inherently unsafe, and should be sanitized/validated accordingly.

How to pass a search $_GET parameter to a new custom search page?

Problem is that ‘s’ param is a standard query param of WordPress, when you use the url /custom-search?s=mysearchstring your are saying to WordPress to retrieve the page ‘custom-search’ that contain the string ‘mysearchstring’ and this bring a 404. You have 2 possibilities: use another query string name, something like /custom-search?cs=mysearchstring then inside the page template … Read more

Exclude pages from WordPress search result page

Add this to your child themes functions file using a code editor like Notepad++. You will need to change the page I.D’s in the code to your own. Exclude Specific Pages From Search Results add_filter( ‘pre_get_posts’, ‘exclude_pages_search_when_logged_in’ ); function exclude_pages_search_when_logged_in($query) { if ( $query->is_search && is_user_logged_in() ) $query->set( ‘post__not_in’, array( 1, 2, 3, 4, 5 … Read more

Search only blog posts (default WP search widget)

@PieterGoosen has a good description on why your pre_get_posts callback is giving you a problem. Here’s an alternative workaround to restrict the native search widget to the post post type: /** * Restrict native search widgets to the ‘post’ post type */ add_filter( ‘widget_title’, function( $title, $instance, $id_base ) { // Target the search base … Read more

Link to search page without search parameter

Create a file search.php inside your theme-folder. In this file you can design the search page and its functionality. Typically search page looks like this, <?php /** * The template for displaying search results pages * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result * * @package Torba_Market */ get_header(); ?> <div class=”container”> <section id=”primary” class=”content-area”> <main id=”main” class=”site-main” role=”main”> … Read more

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