-
I am using the same query loop block element setup described here:
https://generate.support/topic/element-for-site-search-bar/#post-126253
Works great except that on the Search Results page the navigation indicates there are (for example) 5 pages of results, when in fact there are only 2. This doesn’t happen on the product archive pages, which utilize the same element. Also, I have the Woocommerce product search widget in my footer, which displays results using this element as well, and the navigation is correct on those results pages.
If this is a difficult fix, another question would be: is there a way to connect the search modal in the navigation to the woocommerce product search rather than the default WP search?
Thanks for your help.
-
Hi there,
Works great except that on the Search Results page the navigation indicates there are (for example) 5 pages of results, when in fact there are only 2.
How did you add the post-number indicator? I don’t see it in David’s code in the referencing topic.
Can I see your search result page?
is there a way to connect the search modal in the navigation to the woocommerce product search rather than the default WP search?
The search modal can search products, not sure what you mean. Can you explain some more?
-
Hi Ying. I’m not sure what you mean by “post-number indicator.” If you go to https://wsedev.wpengine.com and use the search modal in the navigation, I think you will see what I mean. For example, if you search for “orange” there will be 6 results (less than a full page), but the navigation indicates there are 3 pages of results.
-
Oh, you were referring to the pagination, it indicates that there are 3 pages, which means there are at least 13 posts.
David’s code should not affect the pagination, it’s just to modify the title.
Do you have any other custom functions that would change the loop on the search result page?
-
I’ve realized that when the search modal shows there are 8 pages of results (for example) when there are really only 3, if I search using the WC Product Search widget (in footer) there actually are 8 pages of results, and they are much more accurate results.
The only custom function affecting the loop is this, to sort by stock status:
add_filter( ‘generateblocks_query_loop_args’, function( $query_args, $attributes ) {
// Apply filter if loop has class: sort-by-stock
if ( ! is_admin() && ! empty( $attributes[‘className’] ) && strpos( $attributes[‘className’], ‘sort-by-stock’ ) !== false ) {
$query_args = array_merge( $query_args, array(
‘orderby’ => array(
‘meta_value’ => ‘ASC’,
‘title’ => ‘ASC’
),
‘meta_key’ => ‘_stock_status’,
‘meta_type’ => ‘CHAR’
));
}
return $query_args;
}, 10, 2 ); -
Can you try adding this
sort-by-stock
class to the pagination button blocks as well? -
I tried it, but it didn’t seem to make a difference. But what does seem to solve my issue is this:
add_action( ‘generate_inside_search_modal_form’, function() {
printf( ‘<input type=”hidden” name=”post_type” value=”product” />’ );
} );which I found in the thread: https://generate.support/topic/new-navigation-search-modal-output-for-products/#post-11070
-
The only other thing I need to do is to exclude certain categories from the search results. Do you know how to do that?
-
Nevermind, I found a snippet to do that. Thanks for your help!
-
Glad you found it out 🙂
- You must be logged in to reply to this topic.