enter image description here

In wordpress search, I am trying to search only post type “products”.
However it’s still showing my “journal posts”.
But even weirder than this, when I search for the word “shoes” the theme can’t seem to find anything at all. I am using a plugin called “search-everything” to allow my search to extend to some extra post features like tags, (I have tagged the word “shoes” an all shoe products and even used the word “shoes” in the product title, which is something wordpress looks into even without any search plugins.
Apart from this, the search template is working decently.

Please have a look at the website to test it: http://jadepalacecollective.com/?s=shoes

Example above is a search for “mules”.
and it’s also retrieving a post from the journal (the big image on the bottom)

This is my code (I have slimmed it down for readability’s sake)
I first go to this main search.php page

<?php
    if (get_post_type() == 'product' ) : ?>

        <header class="page-header">
            <h1 class="page-title searchresults-for"><?php printf( esc_html__( 'Search Results for: %s', 'palace' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
        </header><!-- .page-header -->

        <?php
        /* Start the Loop */
        while ( have_posts() ) : the_post();
            get_template_part( 'template-parts/content', 'search' );
        endwhile;
    else :
        get_template_part( 'template-parts/content', 'none' );
    endif; ?>

If the search.php finds something it then fetches the template search-content.php to display some info about the product.

<?php   if (get_post_type() == 'product' ) : ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

 <a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail(); ?>
 </a>
</article><!-- #post-## -->
<?php endif; ?>

Read more here: Why is my product search displaying journal posts and why is it not working at all with the term “shoes”?


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: