do_shortcode from ajax response
-
Hi Philipp,
I have a custom field that stores the gallery shortcode:
[gallery link="none" size="full" slick_active="true" ids="1915,1916,1917,1918,1919" sl_show_caption="true"]
I am looking to process the shortcode via ajax and put the HTML response in a container on the page.
I am retrieving the value when the user clicks on a selection and responding with a JSON object:
PHP
$return = array( 'acquired' => get_post_meta($id, '_property_acquired', true), 'address' => get_post_meta($id, '_property_address', true), 'property' => get_post_field('post_title', $id), 'rsf' => get_post_meta($id, '_property_rsf', true), 'sold' => get_post_meta($id, '_property_sold', true), 'slider' => do_shortcode(get_post_meta($id, '_property_transformation_slider', true)) ); wp_send_json($return);
JS
$('#transformation-slider').html(data.slider).slick()
The HTML string that I get back from the JSON response is of the normal WP gallery, and NOT one formatted for Slick slider. If I do
do_shortcode(get_post_meta($id, '_property_transformation_slider', true))
directly in the page template the slider renders as expected. I am adding the Slick CSS and JS to the page via the method described in your FAQ under ‘Is it possible to use slick’s JS and CSS independently?’Hope this is clear. Any help would be appreciated. I should be able to put up a page if noting sticks out. Thanks.
- The topic ‘do_shortcode from ajax response’ is closed to new replies.