Search
How to Update my theme search template if products link are incorrect - WP Global Cart
14835
post-template-default,single,single-post,postid-14835,single-format-standard,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.0,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,eltd-fullscreen-search eltd-search-fade,eltd-side-menu-slide-from-right,wpb-js-composer js-comp-ver-6.3.0,vc_responsive
 

How to Update my theme search template if products link are incorrect

WP Global Cart / Articles  / How to Update my theme search template if products link are incorrect
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

How to Update my theme search template if products link are incorrect

When doing a WooCommerce MultiSite Search, the results are returned often within WooCommerce template called archive-product.php This is managed automatically through the internal code to return appropriate product link, depending on the shop in the network where is being located.
Some of WordPress Themes use their own search template. A commonplace for such code is the search.php file, within the theme directory. Using the default WordPress editor or a specialized tool, edit that file as follow:

Locate the following code in the template file:

 			while ( have_posts() ) :
				the_post();

				get_template_part( 'template-parts/content/content', 'excerpt' );
                
			endwhile;

This need a bit of update to include the switch_to_blog() and restore_current_blog() so add the 2 new lines:

			while ( have_posts() ) :
				the_post();
                
                if  ( isset($post->blog_id) ) { switch_to_blog ($post->blog_id); }

				get_template_part( 'template-parts/content/content', 'excerpt' );
                
                if  ( isset($post->blog_id) ) { restore_current_blog(); }

			endwhile;

At this point the products within the search interface include the correct links.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x