• Resolved rmixr

    (@rmixr)


    Hi,
    I made a custom search to search on my custom post (docutheque).
    It works for the default language (fr) when I search for a french term on the french version of the site, but it doesn’t in the secondary language (en).
    When I search an english term on the english version, it returns no results.
    If I search french term in the english version, it returns results in english.

    Here is the code :
    $keyword = sanitize_text_field( $_POST[‘keyword’] );
    $args = array(
    ‘s’ => $keyword,
    ‘post_type’ => ‘docutheque’,
    ‘post_status’ => ‘publish’,
    ‘orderby’ => ‘publish_date’,
    ‘order’ => ‘DESC’,
    ‘posts_per_page’ => 6,
    ‘paged’ => 1,
    );
    $posts = new WP_Query( $args );

    Any Idea ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    You can use WP_Query with the query[‘s’] parameter and it will work out-of-the-box to provide relevant posts for that key term.
    The key term needs to be in same language as the current language being displayed when loading that page. In code, posts returned will be in the default language (IDs, post title, post content etc.) but the content echoed is translated on a later hook, so it will be displayed in the translated language in front-end.
    Only post title and post content are searchable in translated languages, external custom fields such as ACF are not. Depending on your setup, if you can include custom fields content inside the_content hook, then the custom fields are searchable as well.
    For the search to work on a specific post in a specific language, translation of that post content and title in that same language must exist prior to searching. If automatic translation is active, a post must be visited at least once in that specific language in order to get indexed by TP.

    Hope this helps!
    Cheers,

    Thread Starter rmixr

    (@rmixr)

    Hello Denis,
    thanks for your answer.
    I’ve always seen this answer, but as you can see in my post, I’m using the WP_Query with the “s” parameter but it doesn’t works as expected.
    I’m using the last version of the plugin.

    Thread Starter rmixr

    (@rmixr)

    Hi all,
    anyone with the same issue ?

    Thread Starter rmixr

    (@rmixr)

    @sdenis, the issue seems to be in the include/class-search.php line 40 :
    if ( ( !is_admin() && $query->is_main_query() && $query->is_search() ) || apply_filters( ‘trp_force_search’, false ) ) {

    In my case “$query->is_main_query() && $query->is_search()” are never both at true.

    If I comment this, the query works fine.

    Any ideas ?

    Plugin Support Alex

    (@alexcozmoslabs)

    We need to take the pulse of this ticket. Is it still relevant?
    In the meantime, I set this ticket as Resolved. You can also change its status back to unresolved and let us know by replying to this topic if your request still needs attention.
    Another option is to leave this ticket as it is and open a new one where to mention the issue again and ask for support.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom search with TranslatePress’ is closed to new replies.