codex - How to disable Wp-Page Navigation on Blank Search in Wordpress

admin2025-06-05  1

Im using the Following Code in search.php

<?php if (have_posts() && strlen( trim(get_search_query()) ) != 0 ) : while (have_posts()) : the_post(); ?>

<?php endwhile; else:?> <b>No results match your search.</b> <p>For Accurate results, Please Search the Model Number of the device or the Brand Name.</p> <?php endif; ?>

<div class="navigation"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> <?php } ?></div>

Functions.php:

function SearchFilter($query) {
    // If 's' request variable is set but empty
    if (isset($_GET['s']) && empty($_GET['s']) && $query->is_main_query()){
        $query->is_search = true;
        $query->is_home = false;
    }
    return $query;}
add_filter('pre_get_posts','SearchFilter');

How to disable the navigation in black search?

Im using the Following Code in search.php

<?php if (have_posts() && strlen( trim(get_search_query()) ) != 0 ) : while (have_posts()) : the_post(); ?>

<?php endwhile; else:?> <b>No results match your search.</b> <p>For Accurate results, Please Search the Model Number of the device or the Brand Name.</p> <?php endif; ?>

<div class="navigation"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?> <?php } ?></div>

Functions.php:

function SearchFilter($query) {
    // If 's' request variable is set but empty
    if (isset($_GET['s']) && empty($_GET['s']) && $query->is_main_query()){
        $query->is_search = true;
        $query->is_home = false;
    }
    return $query;}
add_filter('pre_get_posts','SearchFilter');

How to disable the navigation in black search?

Share Improve this question asked Dec 29, 2018 at 19:04 Rajesh PatelRajesh Patel 11 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Can you try this at search.php

<?php if ( have_posts() && strlen( trim( get_search_query() ) ) != 0 ) : while ( have_posts() ) : the_post();  // Start of the loop.?>
    <?php  // Do code for the loop. ?>
<?php endwhile;  // End of the loop. ?>
    <div class="navigation">
        <?php 
            if( function_exists( 'wp_pagenavi' ) ) { 
                wp_pagenavi(); 
            }
        ?>
    </div>
<?php else:?> 
    <b>No results match your search.</b> 
    <p>For Accurate results, Please Search the Model Number of the device or the Brand Name.</p> 
<?php 
endif; 
?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749060347a316014.html

最新回复(0)