• Resolved combobreaker

    (@combobreaker)


    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Philipp Bammes

    (@tyrannous)

    Hi @combobreaker,
    thanks for the detailed bug report!

    As you wrote, adding echo do_shortcode( get_post_meta( $id, 'meta_key', true ) ); directly in the template renders the slider correctly. Technically, it shouldn’t make any difference where a function is called, be it in the template or in the function that generates the AJAX output.

    So why does it differ? Under certain circumstances, the browser will cache AJAX calls. Make sure to clear it.

    If you still get native gallery HTML code please make the theme or plugin you’re working on available to me (publish it on GitHub or Bitbucket, post a link to a zip file etc.). Otherwise I won’t be able to test this because I can’t reverse engineer your setup.

    Thanks!

    Thread Starter combobreaker

    (@combobreaker)

    Thanks Philipp,

    I’d like to give you access to the repo on BitBucket if you don’t mind. It looks like you have two user names over there.

    I think it may be easier if I contact via Slack. Is that okay with you?

    • This reply was modified 6 years, 3 months ago by combobreaker.
    Plugin Author Philipp Bammes

    (@tyrannous)

    Sure. You’ll find my Slack user name on my profile page.

    Philipp helped me out and found an issue because the AJAX calls are handled in admin. He included the fix in his next update, but if someone needs a fix before then you can add the code below to your functions.php.

    add_action('init', array(
      'Slick_Slider_Output',
      'init_slider'
    ));
    Thread Starter combobreaker

    (@combobreaker)

    Above post is from me. Logged into different account by mistake. Marking as resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘do_shortcode from ajax response’ is closed to new replies.