Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1073812

    Hello Sirs,

    I use search only for products and I use the grid layout in the search results.

    @Ismael
    supported me giving the following code for search.php:

    I replaced: get_template_part( ‘includes/loop’, ‘search’ );

    With:

    global $posts;
    $post_ids = array();
    foreach($posts as $post) $post_ids[] = $post->ID;

    if(!empty($post_ids))
    {
    $atts = array(
    ‘type’ => ‘grid’,
    ‘items’ => get_option(‘posts_per_page’),
    ‘columns’ => 3,
    ‘class’ => ‘avia-builder-el-no-sibling’,
    ‘paginate’ => ‘yes’,
    ‘use_main_query_pagination’ => ‘yes’,
    ‘custom_query’ => array( ‘post__in’=>$post_ids, ‘post_type’=>get_post_types() )
    );

    $blog = new avia_product_slider($atts);
    $blog->query_entries();
    echo “<div class=’entry-content-wrapper’>”.$blog->html().”</div>”;
    }

    My issue now is when the search doesn’t find any product, the term: “Nothing Found” is missing from the search results.

    Best regards,
    Nick

    • This topic was modified 5 years, 8 months ago by nickgin.
    #1075623

    Hey nickgin,

    You need to check if you got anything back and show appropriate message.

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1075653

    Hi Victoria,

    Thank you for your quick reply.

    Could you help me on that please?

    Best regards,
    Nick

    #1077184

    Hi,

    Thanks for the update.

    Can you provide the whole content of the file or modification? Please post it on pastebin. We’ll check this again afterwards.

    Best regards,
    Ismael

    #1077194

    Hi Ismael,

    Thank you for your excellent support! I really appreciate it!

    I am providing you the whole content of search.php:

    <?php
    if ( !defined(‘ABSPATH’) ){ die(); }

    global $avia_config;

    /*
    * get_header is a basic wordpress function, used to retrieve the header.php file in your theme directory.
    */
    get_header();

    // allows to customize the layout
    do_action( ‘ava_search_after_get_header’ );

    $results = avia_which_archive();
    echo avia_title(array(‘title’ => $results ));

    do_action( ‘ava_after_main_title’ );
    ?>

    <div class=’container_wrap container_wrap_first main_color <?php avia_layout_class( ‘main’ ); ?>’>

    <div class=’container’>

    <main class=’content template-search <?php avia_layout_class( ‘content’ ); ?> units’ <?php avia_markup_helper(array(‘context’ => ‘content’));?>>

    <div class=’page-heading-container clearfix’>
    <section class=”search_form_field”>
    <?php
    echo “<h4>”.__(‘New Search’,’avia_framework’).”</h4>”;
    echo “<p>”.__(‘If you are not happy with the results below please do another search’,’avia_framework’).”</p>”;

    get_search_form();
    echo “<span class=’author-extra-border’></span>”;
    ?>
    </section>
    </div>

    <?php
    if(!empty($_GET[‘s’]) || have_posts())
    {
    echo “<h4 class=’extra-mini-title widgettitle’>{$results}</h4>”;

    /* Run the loop to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-search.php and that will be used instead.
    */
    $more = 0;
    global $posts;
    $post_ids = array();
    foreach($posts as $post) $post_ids[] = $post->ID;

    if(!empty($post_ids))
    {
    $atts = array(
    ‘type’ => ‘grid’,
    ‘items’ => get_option(‘posts_per_page’),
    ‘columns’ => 4,
    ‘class’ => ‘avia-builder-el-no-sibling’,
    ‘paginate’ => ‘yes’,
    ‘use_main_query_pagination’ => ‘yes’,
    ‘custom_query’ => array( ‘post__in’=>$post_ids, ‘post_type’=>get_post_types() )
    );

    $blog = new avia_product_slider($atts);
    $blog->query_entries();
    echo “<div class=’entry-content-wrapper’>”.$blog->html().”</div>”;
    }

    }

    ?>

    <!–end content–>
    </main>

    <?php

    //get the sidebar
    $avia_config[‘currently_viewing’] = ‘page’;

    get_sidebar();

    ?>

    </div><!–end container–>

    </div><!– close default .container_wrap element –>

    <?php get_footer(); ?>

    I am looking forward to your news.

    Best regards,
    Nick

    #1077364

    Hi,

    Thanks for the update.

    Try to put this code:

    
    if(empty($post_ids)) {
        echo "<div class='entry-content-wrapper'>".__('No products found.', 'avia_framework')."</div>";
    }
    

    .. right after this line:

    echo “<div class=’entry-content-wrapper’>”.$blog->html().”</div>”;
    

    Best regards,
    Ismael

    #1077416

    Hi Ismael,

    Thank you for your quick reply.
    Unfortunately, nothing happed.
    I am providing you additional information:
    Page URL: https://zoomit.gr/wordpress_2/?s=fdgfdgdgdf
    screenshot: https://prnt.sc/mwd5tn

    Whole search.php with your modification:

    <?php
    if ( !defined(‘ABSPATH’) ){ die(); }

    global $avia_config;

    /*
    * get_header is a basic wordpress function, used to retrieve the header.php file in your theme directory.
    */
    get_header();

    // allows to customize the layout
    do_action( ‘ava_search_after_get_header’ );

    $results = avia_which_archive();
    echo avia_title(array(‘title’ => $results ));

    do_action( ‘ava_after_main_title’ );
    ?>

    <div class=’container_wrap container_wrap_first main_color <?php avia_layout_class( ‘main’ ); ?>’>

    <div class=’container’>

    <main class=’content template-search <?php avia_layout_class( ‘content’ ); ?> units’ <?php avia_markup_helper(array(‘context’ => ‘content’));?>>

    <div class=’page-heading-container clearfix’>
    <section class=”search_form_field”>
    <?php
    echo “<h4>”.__(‘New Search’,’avia_framework’).”</h4>”;
    echo “<p>”.__(‘If you are not happy with the results below please do another search’,’avia_framework’).”</p>”;

    get_search_form();
    echo “<span class=’author-extra-border’></span>”;
    ?>
    </section>
    </div>

    <?php
    if(!empty($_GET[‘s’]) || have_posts())
    {
    echo “<h4 class=’extra-mini-title widgettitle’>{$results}</h4>”;

    /* Run the loop to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-search.php and that will be used instead.
    */
    $more = 0;
    global $posts;
    $post_ids = array();
    foreach($posts as $post) $post_ids[] = $post->ID;

    if(!empty($post_ids))
    {
    $atts = array(
    ‘type’ => ‘grid’,
    ‘items’ => get_option(‘posts_per_page’),
    ‘columns’ => 4,
    ‘class’ => ‘avia-builder-el-no-sibling’,
    ‘paginate’ => ‘yes’,
    ‘use_main_query_pagination’ => ‘yes’,
    ‘custom_query’ => array( ‘post__in’=>$post_ids, ‘post_type’=>get_post_types() )
    );

    $blog = new avia_product_slider($atts);
    $blog->query_entries();
    echo “<div class=’entry-content-wrapper’>”.$blog->html().”</div>”;
    if(empty($post_ids)) {
    echo “<div class=’entry-content-wrapper’>”.__(‘No products found.’, ‘avia_framework’).”</div>”;
    }
    }

    }

    ?>

    <!–end content–>
    </main>

    <?php

    //get the sidebar
    $avia_config[‘currently_viewing’] = ‘page’;

    get_sidebar();

    ?>

    </div><!–end container–>

    </div><!– close default .container_wrap element –>

    <?php get_footer(); ?>

    I am looking forward to your news.

    Best regards,
    Nick

    #1078459

    Hi,

    Can you paste the code to pastebin please, so it is easier for us to read?

    Best regards,
    Basilis

    #1078493

    Hi Basilis,

    Thank you for your support!
    Yes, of course.
    https://pastebin.com/eDKj8bHh

    I am looking forward to your news.

    Best regards,
    Nick

    #1079808

    Hi,

    Thanks for the update.

    We modified the code a bit. Please try it again.

    // https://pastebin.com/rX2rW7Dq

    Best regards,
    Ismael

    #1079987

    Hi Ismael,
    One more time you are great! The best moderator!!!

    Thank you so much!
    You can close this ticket.

    Best regards,
    Nick

    #1080908

    Hi,

    You’re welcome. Glad we could help!

    Have a nice day.

    Best regards,
    Ismael

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Nothing found search result issue’ is closed to new replies.