WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Search results : only in specific language (5 posts)

  1. Zurd
    Member
    Posted 1 year ago #

    When using the Search function of WordPress, it returns all pages from all languages. Is there a way to modify it to only show page languages that I'm in ?

    http://wordpress.org/extend/plugins/polylang/

  2. Zurd
    Member
    Posted 1 year ago #

    This is the code that loops in my search.php file that prints every page title. If there was only a way to test what language is for the_post()

    <?php while (have_posts()) : the_post(); ?>

    <div <?php post_class() ?>>
    <h3 id="post-<?php the_ID(); ?>">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>

    </h3>
    </div>

    <?php endwhile; ?>

  3. Zurd
    Member
    Posted 1 year ago #

    Solved, here's the code I used, it's the search form :

    <?php
    $currentlang = get_bloginfo('language');
    if ( $currentlang=="en-CA" ) {
      echo "<h2>Search</h2>";
      echo '<form method="get" id="searchform" action="' . site_url() . '/en/">';
    }
    else {
      echo "<h2>Recherche</h2>";
      echo '<form method="get" id="searchform" action="' . site_url() .'/fr/">';
    }
    ?>
    
    <input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" size="15" />
    <input type="submit" value=">" />
    </form>
  4. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, or you could have used:

    echo "<h2>" . __('Search', 'your_theme_textdomain') . "</h2>";
    echo '<form method="get" id="searchform" action="' . home_url() . '">';

    as Polylang automatically modifies the home url according to the language and does not modify the site url as it is not language dependant.

    At first line, I used the translation function of WordPress using po/mo files

  5. Zurd
    Member
    Posted 1 year ago #

    Using the home_url instead of site_url just takes me back to my homepage without any search results.

    Using the translation po/mo files of wordpress is better than what I do but what I did is already working and I don't have no po or mo files to compile, yes, I'm lazy.

    Thanks for providing us polylang, this is the best translation plugin I ever used, if I ever finish the 2 websites that is using it, I'll donate, thanks again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.