New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPML Filter dropdown shows all values from different languages #274

Closed
DGStefan opened this Issue Oct 20, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@DGStefan
Member

DGStefan commented Oct 20, 2015

@DGStefan DGStefan added this to the Requested features milestone Oct 20, 2015

@tobiasschutter tobiasschutter modified the milestones: 3.8, Requested features Nov 25, 2015

@tobiasschutter tobiasschutter modified the milestones: 3.9, 3.8 Mar 8, 2016

@tobiasschutter

This comment has been minimized.

Show comment
Hide comment
@tobiasschutter

tobiasschutter Mar 25, 2016

Member

Currently we retrieve most values directly from the DB, surpassing all filters. In order to make it work with WPML we would need to use the WP_Query object. This could slow down the query needed to retrieve the filter values.

Member

tobiasschutter commented Mar 25, 2016

Currently we retrieve most values directly from the DB, surpassing all filters. In order to make it work with WPML we would need to use the WP_Query object. This could slow down the query needed to retrieve the filter values.

@inBytes

This comment has been minimized.

Show comment
Hide comment
@inBytes

inBytes Mar 28, 2016

Just in case it helps, we are sorting out this issue from a long time, like this:

/**
* HOOK: cac/addon/filtering/options
* TYPE: Filter
* SCOPE: Plugin (Admin Columns PRO)
* 
* Use this filter to change the options of the filtering dropdown. We are using it to show only the elements that belongs to the actual language
* 
* @author inBytes
* @param Array                  $arrOptions     An array containing all the Options that are going to be rendered
* @param Object (CPAC_Column)   $objColumn      Data associated with the column
* @return Array                 $arrOptions
*/

if ( is_admin() )    
    add_filter( 'cac/addon/filtering/options', 'fncFilterCombosACF', 10, 2 );

function fncFilterCombosACF( $arrOptions, $objColumn ) {

    global $wpdb;

    // (Only for) ACF Column
    if ( $objColumn->get_type() == 'column-acf_field' ) {

        // Get the field behind the actual column
        $arrField = $objColumn->get_field();

        // (Depending on the) ACF Field Name
        //  ** ADD HERE WITH ORs (||) EVERY ACF FIELD THAT HAS TRANSLATIONS
        if ( $arrField['name']  == 'my_CPT_slug_1' || 
             $arrField['label'] == 'My CPT Label' || 
             $arrField['name']  == 'my_CPT_slug_2'           ||
             $arrField['name']  == 'my_CPT_slug_3'
           ) {

            // Convert the Keys of the Options (=IDs of the Posts) into a string of comma-separated elements
            $sElements = implode( ',', array_keys($arrOptions) );

            // Select the Elements from WPML from this IDs, and filter only the ones relative to the actual language
            $sSQL = $wpdb->prepare( "SELECT element_id 
                                     FROM wp_icl_translations 
                                     WHERE element_id IN ($sElements)
                                       AND language_code = %s", ICL_LANGUAGE_CODE );
            $arrElementsWPML = $wpdb->get_results( $sSQL );

            // Filter the Options, with only the ones relatives to the actual language
            foreach( $arrElementsWPML as $row )
                $arrOptionsFiltered[ $row->element_id ] = $arrOptions[ $row->element_id ];

            $arrOptions = $arrOptionsFiltered;
        }
    }

    return $arrOptions;
}

inBytes commented Mar 28, 2016

Just in case it helps, we are sorting out this issue from a long time, like this:

/**
* HOOK: cac/addon/filtering/options
* TYPE: Filter
* SCOPE: Plugin (Admin Columns PRO)
* 
* Use this filter to change the options of the filtering dropdown. We are using it to show only the elements that belongs to the actual language
* 
* @author inBytes
* @param Array                  $arrOptions     An array containing all the Options that are going to be rendered
* @param Object (CPAC_Column)   $objColumn      Data associated with the column
* @return Array                 $arrOptions
*/

if ( is_admin() )    
    add_filter( 'cac/addon/filtering/options', 'fncFilterCombosACF', 10, 2 );

function fncFilterCombosACF( $arrOptions, $objColumn ) {

    global $wpdb;

    // (Only for) ACF Column
    if ( $objColumn->get_type() == 'column-acf_field' ) {

        // Get the field behind the actual column
        $arrField = $objColumn->get_field();

        // (Depending on the) ACF Field Name
        //  ** ADD HERE WITH ORs (||) EVERY ACF FIELD THAT HAS TRANSLATIONS
        if ( $arrField['name']  == 'my_CPT_slug_1' || 
             $arrField['label'] == 'My CPT Label' || 
             $arrField['name']  == 'my_CPT_slug_2'           ||
             $arrField['name']  == 'my_CPT_slug_3'
           ) {

            // Convert the Keys of the Options (=IDs of the Posts) into a string of comma-separated elements
            $sElements = implode( ',', array_keys($arrOptions) );

            // Select the Elements from WPML from this IDs, and filter only the ones relative to the actual language
            $sSQL = $wpdb->prepare( "SELECT element_id 
                                     FROM wp_icl_translations 
                                     WHERE element_id IN ($sElements)
                                       AND language_code = %s", ICL_LANGUAGE_CODE );
            $arrElementsWPML = $wpdb->get_results( $sSQL );

            // Filter the Options, with only the ones relatives to the actual language
            foreach( $arrElementsWPML as $row )
                $arrOptionsFiltered[ $row->element_id ] = $arrOptions[ $row->element_id ];

            $arrOptions = $arrOptionsFiltered;
        }
    }

    return $arrOptions;
}

@DGStefan DGStefan modified the milestones: 3.10, 3.9 May 31, 2016

@tobiasschutter tobiasschutter modified the milestones: Future Release, 4.1 Apr 26, 2017

@DGStefan

This comment has been minimized.

Show comment
Hide comment
@DGStefan

DGStefan Dec 13, 2017

Member

Issued will be closed.

Member

DGStefan commented Dec 13, 2017

Issued will be closed.

@DGStefan DGStefan closed this Dec 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment