WordPress.org

Ready to get started?Download WordPress

Forums

Switch Site Rewrite
[resolved] switch_to_blog permalinks search multisite (6 posts)

  1. shackep
    Member
    Posted 2 years ago #

    I have given this a go but still no joy. It may be that I am encountering some W3 Total Cache issues. I am using switch_to_blog in a sitewide search powered by Relevanssi.

    The search itself works, as I am getting all the expected results, just the permalinks are pointing to all sorts of places.

    <input type="hidden" name="searchblogs" value="1,2,4" />

    <?php switch_to_blog($post->blog_id); ?>

    I have also tried flushing cache.

    Point me in the right direction?

    Many thanks!

    http://wordpress.org/extend/plugins/switch-site-rewrite/

  2. Mikko Saari
    Member
    Posted 2 years ago #

    Show me your search results template, or the part of it that prints out the posts. Is the switch_to_blog() in there at the right spot?

  3. shackep
    Member
    Posted 2 years ago #

    I have it built to have people be able to search the blog they are on first. If they want to broaden their search results there is another search field on the results page that pulls from the specific set of blogs. The loop is a little more complicated because it is a Wootheme's Canvas loop.

    <?php
    /**
     * Loop - Search
     *
     * This is the loop logic used on the search results screen.
     *
     * @package WooFramework
     * @subpackage Template
     */
     global $more; $more = 0;
    
    woo_loop_before();
    if (have_posts()) { $count = 0;
    
    	$title_before = '<span class="archive_header">';
    	$title_after = '</span>';
    
    	//echo $title_before . sprintf( __( 'Search results for &quot;%s&quot;', 'woothemes' ), get_search_query() ) . $title_after;
    ?>
    <h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' &mdash; '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2><hr>
    
    <div>
    <h3>Not finding what you are looking for? Search all FMCUSA sites.</h3><form method="get" action="http://fmcusa.org/">
    	<span class="fr secondary-search">
    		<input type="text" value="To search, type and hit enter..." name="s" id="s" onfocus="if (this.value == 'To search, type and hit enter...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'To search, type and hit enter...';}" />
    		<input type="hidden" id="searchsubmit" value="Search" />
    		<input type="hidden" name="searchblogs" value="34,35,13,14,15,37,50,48,9" />
    </form></span>
    </div>
    &nbsp;
    <hr>
    <div class="fix"></div>
    <?php switch_to_blog($post->blog_id); ?>
    <?php
    	while (have_posts()) { the_post(); $count++;
    
    		if (get_option('woo_woo_tumblog_switch') == 'true') { $is_tumblog = woo_tumblog_test(); } else { $is_tumblog = false; }
    
    		 $title_before = '<h1 class="title">';
     $title_after = '</h1>';
    
     if ( ! is_single() ) {
    
    	 $title_before = $title_before . '<a href="' . get_permalink( get_the_ID() ) . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
    	 $title_after = '</a>' . $title_after;
    
     }
    
     $page_link_args = apply_filters( 'woothemes_pagelinks_args', array( 'before' => '<div class="page-link">' . __( 'Pages:', 'woothemes' ), 'after' => '</div>' ) );
    
     woo_post_before();
    ?>
    <div <?php post_class(); ?>>
    <?php
    	woo_post_inside_before();
    	the_title( $title_before, $title_after );
    	woo_post_meta();
    ?>
    	<div class="entry">
    	    <?php
    	    	the_excerpt();
    	    	wp_link_pages( $page_link_args );
    	    ?>
    	</div><!-- /.entry -->
    <?php
    	woo_post_inside_after();
    ?>
    </div><!-- /.post -->
    <?php
    	woo_post_after();
    	comments_template();
    
    	} // End WHILE Loop
    } else {
    	get_template_part( 'content', 'noposts' );
    } // End IF Statement
    
    woo_loop_after();
    
    woo_pagenav();
    ?>
  4. Mikko Saari
    Member
    Posted 2 years ago #

    Yeah, you've got the switch_to_blog() call in the wrong place. It should be inside the while (have_posts()) loop.

  5. shackep
    Member
    Posted 2 years ago #

    Thanks! I know have,

    <?php
    	while (have_posts()) { the_post(); $count++;
    	switch_to_blog($post->blog_id);
    		if (get_option('woo_woo_tumblog_switch') == 'true') { $is_tumblog = woo_tumblog_test(); } else { $is_tumblog = false; }
    
    		 $title_before = '<h1 class="title">';
     $title_after = '</h1>';
    
     if ( ! is_single() ) {
    
    	 $title_before = $title_before . '<a href="' . get_permalink( get_the_ID() ) . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">';
    	 $title_after = '</a>' . $title_after;
    
     }
    
     $page_link_args = apply_filters( 'woothemes_pagelinks_args', array( 'before' => '<div class="page-link">' . __( 'Pages:', 'woothemes' ), 'after' => '</div>' ) );
    
     woo_post_before();
    ?>
    and it works.

  6. Frederick Townes
    Member
    Posted 2 years ago #

    switch_to_blog() is supported in the next release.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic