• Resolved s3rg3y

    (@s3rg3y)


    Hi.

    I have image gallery from ACF Repeater and I need send it to the telegram with my post.

    I already have a working code, but it has a fatal flaw:
    ACF fields are updated AFTER sending a message to telegram.

    At the time of my hook, the ACF fields are still not updated and an outdated version of the ACF data is sent along with the post.

    And if I send a newly created post, then at the time of sending the message, the ACF fields are still not filled in.

    The plugin sends messages to telegram BEFORE the ACF fields are updated.

    How to solve this problem?
    How to get updated ACF fields in a hook BEFORE sending a message to telegram?

    Or maybe there is another way to create a gallery from an ACF field Repeater?

    My code:

    add_filter(
    	'wptelegram_pro_p2tg_responses',
    	function ( $responses, $post, $p2tg_instances )
    	{
    	    foreach ($p2tg_instances as $key => $instance)
            {
    			$images = get_field( 'single_slick', $post->ID );
    
    
    			$group_media = [];
    
    			if ( !empty($images) )
    			{
    				foreach ($images as $image)
    				{
    					if( !empty($image['single_slick_image']) )
    					{
    						$group_media[] = [
    							'type' => 'photo',
    							'media' => is_array( $image['single_slick_image'] ) ?  get_attached_file($image['single_slick_image']['id']) : get_attached_file($image['single_slick_image']),
    							'caption' => '',
    							'parse_mode' => $instance['parse_mode']
    						];
    					}
    				}
    			}
    
    			if ( $group_media )
    			{
    				array_push($responses[$key], [
    					'sendMediaGroup' => [
    						'allow_sending_without_reply' => true,
    						'disable_notification'        => $instance['disable_notification'],
    						'media'                       => wp_json_encode( $group_media ),
    						'protect_content'             => $instance['protect_content'],
    					],
    				]);
    			}
            }
    
    		return $responses;
    	},
    	10,
    	3
    );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Irshad Ahmad

    (@irshadahmad21)

    Please do not use this forum to get support for the Pro version.

    You can contact our support on Telegram for that.

    Thread Starter s3rg3y

    (@s3rg3y)

    your advice works, thanks a lot! (Setting 1 minute* Delay in posting* in Post to Telegram settings should fix your problem.)

    • This reply was modified 1 year, 10 months ago by s3rg3y.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to create gallery from ACF Repeater’ is closed to new replies.