I have a WordPress blog which is using a 3rd party theme called Alphabet (it’s no longer available and seems to have been taken down by the creator: https://themeforest.net/item/alphabet-a-responsive-wordpress-blog-theme/14258651)

There are no pages on this site–just blog posts. The search bar works unless you use it on an actual post page. If you use it there, you get a 404 error no matter your search query. Something seems incorrect with how the search result query is appended to the url.

For example, if you use the search on the home page, the url is set up like this:
http://[my-site.com]/?s=test

If you go to a post and use the search there, the url is setup like this:
https://[my-site.com]/[sample-post-title]/?s=Culturalism

If I change the url to exclude the post title, then the search query works. I wouldn’t be surprised if something is wrong with how this 3rd party theme setup the search as it isn’t setup properly by WordPress standards.

Here is the search.php file:

<!-- Start main_content -->
<div class="main_content container">
    <!-- Start posts_sidebar -->
    <div class="posts_sidebar clearfix <?php echo esc_attr($sidebar_position); ?>">

        <!-- Start Sidebar -->
        <?php if (alphabet_get_option('blog_archive_sidebar') == 'Left') {
            get_sidebar();
        } ?>
        <!-- End Sidebar -->

        <!--Start Posts Areaa -->
        <div class="archive_areaa <?php echo esc_attr($fullwidth_position); ?>">
            <div class="row">
                <!-- post_header -->
                <div class="post_header">
                    <h1><?php the_search_query(); ?></h1>
                    <span class="title_divider"></span>
                </div>
                <!-- // post_header -->

                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <!-- Start as_post -->
                    <article class="as_post">
                        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
                            <?php $format = get_post_format();
                            if (false === $format) {
                                $format = 'standard';
                            } ?>
                            <?php get_template_part('includes/content', $format); ?>
                        </div>
                    </article>
                    <!-- End as_post -->
                <?php endwhile; ?>

                    <!-- Start pagination_post -->
                    <nav class="pagination_post">
                        <ul class="pager">
                            <li><?php previous_posts_link(); ?></li>
                            <li><?php next_posts_link(); ?></li>
                        </ul>
                    </nav>
                <?php else : ?>
                    <p><?php esc_html_e('Sorry, no posts matched your criteria.', 'alphabet'); ?></p>
                <?php endif; ?>
                <!-- End pagination_post -->
            </div>
        </div>
        <!--End Posts Areaa -->

        <!-- Start Sidebar -->
        <?php if (alphabet_get_option('blog_archive_sidebar') == 'Right') {
            get_sidebar();
        } ?>
        <!-- End Sidebar -->

    </div>
    <!-- posts_sidebar -->
</div>
<!-- main_content -->

And here is the search form’s code:

 <!-- Start top_search_ico -->
   <div id="top_search_ico">
      <!-- Start top_search -->
      <div class="top_search">
        <form method="get"><input type="text" placeholder="<?php esc_html_e( 'Search and hit enter...', 'alphabet' );?>" name="s" id="s"></form>
        <i class="fa fa-search search-desktop"></i>
      </div>
      <!-- End top_search -->
      <!-- Start top_search_toggle -->
      <div id="top_search_toggle">
        <div id="search_toggle_top">
        <form method="get"><input type="text" placeholder="<?php esc_html_e( 'Search and hit enter...', 'alphabet' );?>" name="s" id="s"></form>
        </div>
        <i class="fa fa-search search-desktop"></i>
      </div>
      <!-- End top_search_toggle -->
    </div>

In case it may be useful, I have the permalinks formatted on the blog as such:
https://[my-site.com]/sample-post/

Read more here: Custom WordPress Theme – Search not working on posts


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: