Forums Forums Search & Filter Pro Search & Filter with WPML

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #139614

    I have two custom post types, Libraries & Resource items.

    Libraries will appear in English and Spanish. For each library, regardless of language, I want all Resource Items to appear in all languages tagged with “certification”. i.e. English, Spanish and Bahasa resource items appearing together on the English Library post type. This should work regardless of if a resource item is a translation of an english resource item, or an independent item. If the resource item is tagged “certification” (or a translated version of the tag), that resource item should appear in these libraries.

    I’m using the Search & Filter pro plugin within the Libraries post type to sort and filter resource items and display the results. Also note I followed this documentation for setting up the Search & Filter form in Spanish: https://www.designsandcode.com/documentation/search-filter-pro/3rd-party/wpml/

    After searching through wpml support tickets, I added the following but it isn’t pulling in all resource items tagged with “Certification,” it’s just showing resource items that match the language the respective Library is set to.

    What do I need to change so all resource items tagged with “certification” appear in a single view, regardless of language?

    Added to functions.php:

    add_action( 'pre_get_posts', 'wpml_custom_query' );
    function wpml_custom_query( $query ) {
     
        if( 'resource-item' == get_post_type() )
            $query->query_vars['suppress_filters'] = true;
     
        return $query;
    }

    added the following to Search & Filter results templates, within child theme:

    $args = array(
          'post_type' => 'resource-item',
          'tag_id' => '151, 348, 419',
          'suppress_filters' => true
    );
    $posts = new WP_Query( $args );

    Links to Libraries”

    English Library: https://preview-dev.rainforest-alliance.org/business/agriculture/libraries/resource-library/ (u/p: ra_demo)
    Spanish Library: https://preview-dev.rainforest-alliance.org/business/agriculture/es/libraries/resource-library (u/p: ra_demo)

    Trevor
    #139634

    Hi

    It is possible that I have misunderstood you, but I want to be sure before I address the concern.

    The way WPML works is to have posts and taxonomy terms translated, and it keeps each language version separated. You want to be able to select a term (like Certification) and see post results from both languages at the same time by joining Certification with the translated term as well?

    Anonymous
    #139682

    Hi Trever, that is correct. It’s also why I thought I could get away with adding the translated IDs to the page template 151, 348, 419 but that didn’t seem to cut it

    Trevor
    #139831

    It is possible you might achieve this by using the Edit Query Arguments filter, but I do not think it would be easy.

    Other users have posted examples of their own usage in the forums, so it might be worth searching for the filter name:

    sf_edit_query_args

    Anonymous
    #139846

    Thanks, Trevor. I tried adding the following to my functions.php but didn’t see the results I was looking for either.

    function filter_function_name( $query_args, $sfid ) {
      //if search form ID = 100, then do something with this query
      if($sfid==261) {
        //modify $query_args here before returning it
        $query_args = array(
          'post_type' => 'resource-item',
          'suppress_filters' => true,
          'orderby' => 'post_date',
          'order' => 'DESC',
          'tag__in' => array( 151, 348, 419 ),
          'posts_per_page' =>  10
        );
      }
      return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    I’ve been searching through the forum, and haven’t been able to find an example that includes the tags.

    Trevor
    #139855

    You code looks right to me (but I could easily be wrong).

    What happens if you tell WPML NOT to translate a particular taxonomy? Does it then keep the same terms for all languages?

Viewing 6 posts - 1 through 6 (of 6 total)