0

The search page, gives results that are sometimes irrelevant. Here is "search.php" :

<div class="list-posts">

<?php if ( have_posts() ): ?>
                <?php while( have_posts() ): ?>
                    <?php the_post(); ?>
<article class="general-post">
    <a href="<?php the_permalink(  ); ?>">
        <div class="image-post">
            
            <img src="<?php the_post_thumbnail_url(  ); ?>" alt="">
        </div>
        <div class="details-general-post">
            <h2><?php the_title(  ); ?></h2>
            <p><?php the_excerpt(  ); ?></p>
        </div>
        <div class="strike">
            <span><p><?php echo get_the_date(); ?> at <?php echo get_the_time( ); ?></p></span>
        </div>
        <div class="tag">
            <?php the_tags(); ?>
        </div>
    </a>
</article>
<?php endwhile;
        else:
    ?>
<div class="title">
    <div class="strike">
        <span><h1>Sorry no posts found. =(</h1></span>
    </div>
</div>
<?php endif;?>
</div>

And the search form :

<form role='search' method='get' action="<?php echo home_url( '/' ); ?>">
  <label for="search">Search</label>
  <input id="search" type="search" pattern=".*\S.*" required value="<?php echo get_search_query() ?>" name="s">
   <span class="caret"></span>
</form>

I have 2 custom post types, "articles" and "news", i want the search to give results from "any", so i tried in "functions.php" :

        if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
            $query->set( 'post_type', 'any' );
        }
    }  
    add_action( 'pre_get_posts', 'tg_include_custom_post_types_in_search_results');

And the problem is, for example: i type in search "DC" and i want all the posts (inclusive the blog posts) that have the tag "DC", but its not working like that at all, it doesn't show the blog posts (sometimes), and sometimes it gives me results that have no connection with "DC", what am i doing wrong?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.