Ecommerce Shopify WordPress Discussion

search form in new custom page template not working

I'm working in Tv shows and movies theme. I have created new page template to display all movies and anther page template to show the tv shows (both custom post type). My search form if any one use it from the index page working fine and shows the result in search.php but if you are in movies page or anther pages the search form takes you to the index page (404 page not created yet) I'm using this code in main header <?php get_search_form();?> this is my searchform.php <form class="d-flex" role="search" methode="get" action="<?php echo esc_url( home_url( '/' ) ) ?>"> <input class="form-control" type="text" name="s" id="search" placeholder="<?php echo ('search in site'); ?>" aria-label="<?php echo ('search'); ?>" value="<?php echo get_search_query() ?>"> <button class="btn btn-outline-success search-btn" type="submit"><i class="fa-solid fa-magnifying-glass"></i></button> </form> this is my search.php <?php get_header(); $search = strtolower(get_search_query()); ?> <?php $args = array( 'taxonomy' => array( 'series' ), // taxonomy name 'hide_empty' => true, 'fields' => 'all', ); $terms = get_terms( $args ); $count = count($terms); if($count > 0){ foreach ($terms as $term) { ?> get_template_part('/assests/series-temp'); <?php } } //code above for returning the custom term of each series post with different loop $args= array( 'post_type'=> array('movies'), 'post_status' => 'publish', 'posts_per_page' => -1, 's' => $search ); $titleQuery = new WP_Query( $args ); if ( $titleQuery->have_posts() ) { while ( $titleQuery->have_posts() ){ $titleQuery->the_post(); ?> <?php if ( get_post_type( get_the_ID() ) == 'movies' ) { get_template_part('/assests/movie-temp'); } ?> <?php } wp_reset_postdata(); } ?> <?php get_footer(); ?> where is my mistakes?? please help
Issue 1: in this their is a typo in this in place of "methode" write a "method" Issue 2: Adlso take care about the correct URL in the form action. If you are on the movies or TV shows page, you want the search to stay within that section of the site.

February 13, 2024

Based on the provided code,Currently you are setting the action attribute to home_url('/'), which will always redirect the form submission to the homepage (/). for that the search form works correctly regardless of the page you are on, you should set the action attribute to the URL of your search results page (search.php). <form class="d-flex" role="search" method="get" action="<?php echo esc_url( home_url( '/search.php' ) ) ?>"> <input class="form-control" type="text" name="s" id="search" placeholder="<?php echo __('Search in site'); ?>" aria-label="<?php echo __('Search'); ?>" value="<?php echo get_search_query() ?>"> <button class="btn btn-outline-success search-btn" type="submit"><i class="fa-solid fa-magnifying-glass"></i></button> </form>

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.