Support

Account

Home Forums Add-ons Gallery Field WPML and Gallery addon problem

Solving

WPML and Gallery addon problem

  • I have installed latest version of WPML, ACF and ACF Gallery addon which I bought.

    This is how I set up all:
    1. Setup 2 languages in WPML
    2. Create Gallery field for post
    3. Marked to “copy from original…” here: /wp-admin/admin.php?page=wpml-translation-management/menu/main.php&sm=mcsetup
    4. added images on original lang to this field (ok)
    5. looked up on second language (ok)
    6. on front getting gallery field for original lang (ok)
    7. second language (PROBLEM)

    I’ve investigated every single file in wpml, acf and acf gallery and found that problem is in /wp-content/plugins/acf-gallery/gallery.php line: 310 which is in this function

    function format_value( $value, $post_id, $field )
    	{
    		$new_value = array();
    		
    		
    		// empty?
    		if( empty($value) )
    		{
    			return $value;
    		}
    		
    		
    		// find attachments (DISTINCT POSTS)
    		$attachments = get_posts(array(
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_status' => null,
    			'post__in' => $value,
    		));
    		
    		$ordered_attachments = array();
    		foreach( $attachments as $attachment)
    		{
    			// create array to hold value data
    			$ordered_attachments[ $attachment->ID ] = array(
    				'id'			=>	$attachment->ID,
    				'alt'			=>	get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
    				'title'			=>	$attachment->post_title,
    				'caption'		=>	$attachment->post_excerpt,
    				'description'	=>	$attachment->post_content,
    				'mime_type'		=>	$attachment->post_mime_type,
    			);
    			
    		}
    		
    		
    		// override value array with attachments
    		foreach( $value as $v)
    		{
    			if( isset($ordered_attachments[ $v ]) )
    			{
    				$new_value[] = $ordered_attachments[ $v ];
    			}
    		}
    		
    		
    		// return value
    		return $new_value;	
    	}

    $value is on both langs ok but problem is heere:

    $attachments = get_posts(array(
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_status' => null,
    			'post__in' => $value,
    		));

    Here I get no $posts on second lang.

  • This is my solution untill you solved out this:

    in your functions.php put this function:

    function custom_get_attachments($ids){
    	GLOBAL $wpdb;
    	$query = "SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID IN ('".implode("','", $ids)."')";
    	$results = $wpdb->get_results($query);
    	return $results;
    }

    and then in gallery.php instead of

    $attachments = get_posts(array(
    			'post_type' => 'attachment',
    			'numberposts' => -1,
    			'post_status' => null,
    			'post__in' => $value,
    		));

    put this
    $attachments = custom_get_attachments($value);

  • Hi @dab.ab.initio

    Thanks for your investigation into this. I think the issue may be fixed by adding a param to the $args array in the original get_posts function.

    Can you please add this to the $args array?
    'suppress_filters' => false,

    Thanks
    E

  • P.S. I bought ACF Gallery addon so I hope there will be soon update which will solve this problem or beta update available here on forum for download.
    Thank you

  • Hi @dab.ab.initio

    Thanks for the follow up.
    Looking at the query args, I’m not sure why the post_status of null is there…

    Can you remove the post_status arg? Does this help?

    Thanks
    E

  • Hi Eliot,

    Nothing happens when I remove this line 🙁

  • Hi @dab.ab.initio

    Thanks for the follow up. I’ve got this on my todo and will do some testing soon.

    Thanks
    E

  • Hi @dab.ab.initio

    I have done lots of testing today with WPML, WPML media and ACF Gallery field.

    In conclusion of the testing, all scenarios worked correctly.

    I believe the issue is caused by the WPML media module. Are you using this module?

    Thanks
    E

  • Exactly same issue here and I’ve got the media module on, since WPML throws an error in the backend if I disable it? Furthermore; disabling it doesn’t seem to make images from the galleries appear.

  • Bump. I bought this plugin for use together with WPML, and will need to make a switch if a fix doesn’t appear within this week.

  • Hi @boetter

    Are you able to setup a test site for me to see the issue myself?
    I am unable to replicate the issue on my end, so I am at a loss as to how to fix it.

    Thanks
    E

  • Alright guys, so i have a little thing i found and i think it’s an issue with some wpml settings (this is probably why @elliot can’t replicate), but i’m still trying to figure which one.

    So, on gallery.php, on format_value method, $value variable contains correct IDs:

    Array ( [0] => 245 [1] => 243 [2] => 241 [3] => 239 [4] => 237 [5] => 235 )

    However!

    // find attachments (DISTINCT POSTS)
    $attachments = get_posts(array(
      'post__in' => $value,
    ....
    ));
    

    Is returning completelly different ids, disregarding post__in option: 235, 237 and so on. Then, when trying to apply the custom ordering, each key is not found (obviously!). This is always happening, no matter how suppress_filters is set.

    Still digin, maybe i find something more. Just wanted to add an update here, maybe someone have a better idea 🙂

    ( also i decided to close this, since is a duplicate: http://support.advancedcustomfields.com/forums/topic/acf-gallery-vs-wpml/ )

  • A little update: as crazy at it may looks, i stopped to have issues as soon i disabled Simple Custom Post Order plugin!

    Still investigating and updating if i find something else.

  • Any update? It is been a long time…

  • Hey guys, I created a fix for this. You can install it as a plugin from here:

    https://github.com/iamntz/acf-gallery-wpml-fix

  • This reply has been marked as private.
Viewing 17 posts - 1 through 17 (of 17 total)

The topic ‘WPML and Gallery addon problem’ is closed to new replies.