website language changes on search results

I there!
I’m pretty new at php so i really appreciate you help on this issue!
I have a website in two languages (english and portuguese, portuguese is the main language) which can be chosen by the user, with a search field for both… the problem is that anytime you look for something that doesn’t exist, the search results appear in portuguese, even if the language picked by the user is the english one!

Do you have any idea why this is happening? Everything else works just fine for both languages!

Thank you so much for your help…

you could have the chosen language stored in a session then have the search query check the language of the session

when you say session, do you mean folder?
???

no a session is like RAM it can store values in memory while the session exists

have a look at this tutorial: http://www.tizag.com/phpT/phpsessions.php

ok, so you mean php session!
I was not working with php sessions, but i read the tutorial carefully and i was trying to implement it on my website, but unfortunately it didn’t work…
I was wondering about having some condition on search. php… like “if the chose language= EN, so the language=EN” so then the php stills showing all the information in english!
I’m really lost at this one!! :’(

I guess you could pass the chosen language in the form query

Thank you… but i really don’t know how to do that! :-[

well if the language is in a get when selected in the url something like language=EN then the language would be the name of the get: $_GET[‘language’] which can then be stored in the search form:

[php][/php]

To be honest your best off using a session would be a much better way of doing it. if you were to try the session approach make sure session_start(); is at the top of each file that will use the session, if you can post your code I might be able to give you better help.

this is my searchform.php

[php]




<input class=“focus” name=“s” type=“text” onfocus=“if(this.value==‘search’) this.value=’’;” onblur=“if(this.value==’’) this.value=‘search’;” value="<?php _e("searchprocurar"); ?>" />
   </fieldset>  
</form>
[/php]

an this is my search.php

[php]<?php get_header(); ?>

          <h1><?php _e("<!--:en-->search result for: <!--:--><!--:PT-->resultados de procura para: <!--:-->"); ?><?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('&#8220;'); echo $key; _e('&#8221;'); _e(' &mdash; '); echo $count . ' '; _e('<!--:en-->articles<!--:--><!--:PT-->artigos<!--:-->'); wp_reset_query(); ?></h1>


          <ul class="mcol">
          <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
          	<li class="article" id="post-<?php the_ID(); ?>">

		<?php
		if ( has_post_thumbnail() ) { ?>
                	<?php 
                	$imgsrcparam = array(
					'alt'	=> trim(strip_tags( $post->post_excerpt )),
					'title'	=> trim(strip_tags( $post->post_title )),
					);
                	$thumbID = get_the_post_thumbnail( $post->ID, 'background', $imgsrcparam ); ?>
                    <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>

                <?php } else {?>
                    <div class="preview"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></a></div>
                <?php } ?>

                <div class="article-over">
                  <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                  <?php the_excerpt(); ?>
                  <div class="postmetadata">
                      <?php the_time(__('y.m.d', 'kubrick')) ?>&nbsp;&#721;&nbsp;
                     
                      <?php printf(__("<!--:en-->categories: %s<!--:--><!--:PT-->categorias: %s<!--:-->"), get_the_category_list(', ')); ?>
                  </div>
                </div>
            </li> <?php ?>
        <?php endwhile; ?>
        <?php else : ?>


        <?php endif; ?>
        </ul>

        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
        <?php endwhile; ?>
        <?php else : ?>
            <h1 id="error"><?php _e("<!--:en-->sorry, but i can't find what you are looking for...<!--:--><!--:PT-->lamentamos, mas não encontramos o que procura...<!--:-->"); ?></h1>
        <?php endif; ?>

        <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
<?php get_footer(); ?>

[/php]

OK it’s WP_Query(“s=$s&showposts=-1”); that will need updating with the current language

so, how do i change that?

I’m assuming you’ll have a column in the table to determine the language to be used if that’s the case it would be something like WP_Query(“s=$s&showposts=-1&lang=$la”);

$la would be the language selected

How do i write a condition like get_language… so on the php before the search results i can make it look for the chose language and give the results according to that!

OK here’s how I normally create a language changer first have the language flags to select a language:

[code]




[/code]

not in the href index.php?la=eng when clicked the la parts becomes the $_GET[‘la’] with a value of eng then I can check if the get is been issues then get the selected language:

[php]session_start();
if($_GET[‘la’]){
$_SESSION[‘la’] = $_GET[‘la’];
header(‘Location:’.$_SERVER[‘PHP_SELF’]);
exit();
}[/php]

As I’ve said before in order to use a session you need to use session_start(); this should be at the top of all pages that need it so in my case I normally put it in a config file as every page includes it, it may be different for you since your using Wordpress.

When $_GET[‘la’] has been set the language is added to a session then the page is reloaded with that language.

forgot to mention you can see a demo of what I’m talking about here http://www.daveismyname.co.uk/demos/languages/index.php

i already tried the php session, but it didn’t work… i guess there’s something to do with wordpress and the searchform i have, cause i’ve been reading a lot of tutorials and trying different solutions… and nothing works!! everytime the search field is used the results only appear in the default language, as well as if in the middle of using the site you click on the home page… again everything returns to the default language!

This is a difficult one…! Thank you for your support…!!!

hmm have you tried starting a session at the top of your template file?

I solved the question related to the home page… there was a “/” on the index.php that was messing the home link!

I’ve tried to start the session on the index.php so then when you open the website you start a new session and then you pick your language and the session keeps that information… i also used the session start on the searchform.php, but that doesn’t make sense cause when you get there you already have your language chose!

I guess the problem is here:
[php]

<?php _e("search result for: resultados de procura para: "); ?><?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('“'); echo $key; _e('”'); _e(' — '); echo $count . ' '; _e('articlesartigos'); wp_reset_query(); ?>

[/php]
on the :
[php]$allsearch = &new WP_Query(“s=$s&showposts=-1”)[/php]
i’ve also tried to change this according to your precious tips, but i was unsuccessful!

The only problem left is the search one!
One more time: a huge thank you!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service