当AJAX在模板部件中调用get\\u theme\\u mod时,是否可以在自定义程序预览窗格中刷新后使其工作?
我有一个主题,可以加载滚动(无限滚动)上的帖子,除了没有在定制器预览中输出更新的主题mods外,其他一切都正常。当我点击保存按钮时,它只输出新的主题mods。
你知道如何在刷新后进行更新吗?
My control settings:
\'id\' => \'show_caption\',
\'type\' => \'select\',
\'section\' => \'caption\',
\'transport\' => \'refresh\',
\'default\' => \'top\',
\'choices\' => array(
\'top\' => __( \'Top\', \'my-domain\' ),
\'bottom\' => __( \'Bottom\', \'my-domain\' ),
),
InfiniteScroll.php:
class InfiniteScroll {
private $query;
public function __construct( WP_Query $query ) {
$this->query = $query;
}
public function register() {
add_action( \'wp_ajax_my_infinite_scroll\', array( $this, \'handleAjax\' ) );
add_action( \'wp_ajax_nopriv_my_infinite_scroll\', array( $this, \'handleAjax\' ) );
add_action( \'wp_enqueue_scripts\', array( $this, \'enqueueScripts\' ) );
}
public function getPosts() {
ob_start();
$this->query->query( $this->getData() );
if ( $this->query->have_posts() ) {
while ( $this->query->have_posts() ) {
$this->query->the_post();
get_template_part( \'template-parts/post/content\' );
}
}
wp_reset_postdata();
return ob_get_clean();
}
public function handleAjax() {
if ( ! check_ajax_referer( \'infinite-scroll-ajax\', \'nonce\' ) ) {
wp_die();
}
wp_send_json_success( $this->getPosts() );
wp_die();
}
// ...
}
content.php:
echo get_theme_mod( \'show_caption\', \'top\' );
Ajax request before customize_save: