Title: selective_refresh issue
Last modified: August 31, 2016

---

# selective_refresh issue

 *  [superskill](https://wordpress.org/support/users/superskill/)
 * (@superskill)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/selective_refresh-issue/)
 * So, I am having an issue with selective refresh, it refreshes the previewer when
   it’s located in a function, like so:
 *     ```
       function text_controller( $setting_id, $section_id, $label = '', $description = '', $default = '', $selector = '', $transport = true, $sanitize = 'sanitize_text_field'  ) {
       	global $wp_customize;
       	if( $transport ) { $transport_type = 'postMessage'; } else { $transport_type = 'refresh'; }
   
       	$wp_customize->add_setting( $setting_id, array(
       		'default'			=> $default,
       		'sanitize_callback' => $sanitize,
       		'capability'		=> 'edit_theme_options',
       		'transport'         => 'postMessage',
       	) );
       	$wp_customize->add_control( $setting_id, array(
       		'label'				=> $label,
       		'description'		=> $description,
       		'section'			=> $section_id,
       		'settings'			=> $setting_id,
       	) );
       	$wp_customize->selective_refresh->add_partial( $setting_id, array(
       		'selector' => $selector,
       		'render_callback' => function( $setting_id ) {
       			return get_theme_mod( $setting_id );
       		},
       	) );
       }
       ```
   
 * I paste all the variables to this function, selective refresh works for like 
   a second and then it refreshes the previewer.
 * If I do the cod outside the function it works.
 * I think it has something to do with this part:
    ` ‘render_callback’ => function(
   $setting_id ) { return get_theme_mod( $setting_id ); },
 * Any suggestions? Thank you!

Viewing 1 replies (of 1 total)

 *  Thread Starter [superskill](https://wordpress.org/support/users/superskill/)
 * (@superskill)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/selective_refresh-issue/#post-7300976)
 * So the solution is:
    `'render_callback' => function() use ( &$setting_id ) {`
   🙂

Viewing 1 replies (of 1 total)

The topic ‘selective_refresh issue’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [superskill](https://wordpress.org/support/users/superskill/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/selective_refresh-issue/#post-7300976)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
