• Resolved Abhijoy Samaddar

    (@abhijoysamaddar01)


    I have a search button in banner and I want to redirect to a custom page and there in a particualr block I want to show the results with while(have_posts()): the_post() code
    Please guide me

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Rafał Groń

    (@aisearch)

    Good news first: there is no Queryra-specific code to write. Queryra hooks pre_get_posts and reorders the main search query, so an ordinary loop already gives you AI-ranked results. Get it working with plain WordPress search first, and Queryra improves the ranking underneath without you touching anything.

    Two things have to be true, and they are almost certainly what is blocking you.

    1. It has to be a real WordPress search. Your banner form must submit a field named s to the site root. If it posts to a custom URL without sis_search() is false and Queryra never runs.
    <form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <input type="search" name="s" value="<?php echo get_search_query(); ?>" /> <button type="submit">Search</button> </form>

    2. Your results block must use the main loop. Queryra only touches the main query by design. A new WP_Query() inside a block is skipped, so you would get plain keyword results there.

    On redirecting to a custom page: you do not need to redirect anywhere. search.php in your theme is the custom page for search results. Put your banner and any other blocks around the loop:
    <?php get_header(); ?> <section class="banner"><!-- your banner --></section> <div class="my-results-block"> <?php if ( have_posts() ) : ?> <h1>Results for "<?php echo get_search_query(); ?>"</h1> <?php while ( have_posts() ) : the_post(); ?> <article <?php post_class(); ?>> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php the_excerpt(); ?> </article> <?php endwhile; ?> <?php the_posts_pagination(); ?> <?php else : ?> <p>Nothing found.</p> <?php endif; ?> </div> <?php get_footer(); ?>

    One trap worth knowing about: do not set orderby in your template or in your own pre_get_posts. Queryra sets orderby => post__in to preserve the relevance ranking. Overriding it re-sorts by date and silently throws the AI ordering away — the results look right, but the order is wrong.

    get_search_query() and pagination both keep working normally.

    Let me know how it goes.

    Plugin Contributor Rafał Groń

    (@aisearch)

    Hi, just checking back on this. I’ll mark it resolved for now, but if it didn’t work on your setup, reply here and I’ll pick it straight back up.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.