ThemeShaper Forums » Thematic

Can someone check this function please?

(6 posts)
  • Started 10 years ago by awarner20
  • Latest reply from awarner20
  • This topic is resolved
  1. This is kind of a specialized function that I'm not sure many people may need, but I wonder if those more familiar with PHP can confirm if it looks correct? What I'm trying to do isn't working and I need to confirm if it's my function or the plugin I'm trying to integrate.

    What am I trying to do?
    I have Thematic installed on a WPMU setup and I've created three blogs, each with their own separate child themes. On the main blog, I am trying to integrate a plugin that allows a user to search across all blogs on an MU setup. This plugin is called wpSearchMu and is located here: http://welcome.totheinter.net/wpsearchmu/

    In the setup instructions for this plugin, you need to add a couple bits of code to the search loop in search.php. So I set off to make a function to filter the search loop. Here it is:

    //**********  FILTER SEARCH LOOP TO ADD WPSEARCHMU PLUGIN CODE  ********************************
    function remove_searchloop() {
        remove_action('thematic_searchloop', 'thematic_search_loop');
    }
    add_action('init', 'remove_searchloop');
    
    function my_wpsearchmu_loop() {
    while ( have_posts() ) : the_post(); ?>
    switch_to_blog($post->blog_id);
    			<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
        			<?php thematic_postheader(); ?>
    				<div class="entry-content">
    <?php thematic_content(); ?>
    
    				</div>
    				<?php thematic_postfooter(); ?>
    			</div><!-- .post -->
    restore_current_blog();
          <?php endwhile;
    }
    add_action('thematic_searchloop', 'my_wpsearchmu_loop');

    After making this change, and following the other instructions on the page above, I still get no search results from other blogs. In fact, it appears that I get no search results from the main blog either.

    In order to get on the correct troubleshooting path, I need to confirm if I've made my function correctly. Can anyone here take a quick peek at this function as it relates to the instructions on the plugin page?

    I would be very grateful:)

    Posted 10 years ago #
  2. Anyone?

    Posted 10 years ago #
  3. Hi Adam,

    here's the working code:

    //**********  FILTER SEARCH LOOP TO ADD WPSEARCHMU PLUGIN CODE  ********************************
    function remove_searchloop() {
        remove_action('thematic_searchloop', 'thematic_search_loop');
    }
    add_action('init', 'remove_searchloop');
    
    function my_wpsearchmu_loop() {
    	global $post;
    	while ( have_posts() ) : the_post();
    		switch_to_blog($post->blog_id); ?>
    		<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    			<?php thematic_postheader(); ?>
    			<div class="entry-content">
    				<?php thematic_content(); ?>
    			</div>
    			<?php thematic_postfooter(); ?>
    		</div><!-- .post -->
    		<?php restore_current_blog();
          endwhile;
    }
    add_action('thematic_searchloop', 'my_wpsearchmu_loop');

    If you're using Windows, try to get Notepad++ to edit PHP files. With its syntax highlighting it's easier to detect errors in the code. :)

    In case that you are a MAC .. ask Amy if she could recommend a good editor.

    Before I forget this one .. and I had to run the indexing in both of my test blogs.

    Chris

    Posted 10 years ago #
  4. I see the difference between your code and mine...thanks so much for the corrections Chris:)

    I'm using Text Wrangler on a Mac. Is there something better I should be using? Amy?

    Chris, when you say "run the indexing on both blogs", do you mean run the wpSearchMu indexing on each blog, or do you mean run this Search Filter on each blog?

    I'm off to get to it...

    Posted 10 years ago #
  5. "Run indexing" means to run the wpSearchMu indexing on each blog. I have this search filter only in the main blog functions file right now and things seem to be working as expected, although I am getting some odd search results.

    Also, if you add a value in the wpSearchMu "Blogs NOT to Index" field, then index process does not run. I'm alerting the developer.

    Posted 10 years ago #
  6. Full full description on how to use this plugin with the above search filter, see here: http://welcome.totheinter.net/wpsearchmu/comment-page-2/#comment-5691

    Posted 10 years ago #

RSS feed for this topic

Reply

You must log in to post.