Support » Developing with WordPress » Sending shortcode string to admin-ajax

  • AJAX and PHP aren’t my strengths, but I’m attempting to create a call that swaps out an existing plugin gallery with a new one. It works for the most part, but the gallery it returns is wrong, same as if the string inside of the shortcode is empty.

    Could I get an extra set of eyes on this to make sure it isn’t some syntax error?

    First the inital shortcode is rendered into the html. Clicking a link sends a new parameter to a js function in the header:

    <div id="vidGalleryContent">
    [tubepress mode="playlist" resultsPerPage='20' output='searchResults' searchProvider='youtube'  playlistValue='PLMffcFdm_7-HT1HiVkNEguRtiYkhgq0TC']
    <a href="#" onclick="swapVidGallery('PLMffcFdm_7-Hi6NibMNpEuc8rlqbBNxC8')">Change gallery</a>

    Then the header script puts the parameter string inside a new shortcode string and sends it off to functions.php:

    function swapVidGallery(vidID){
          var  newGalleryParameter = "[tubepress resultsPerPage='20' output='searchResults' searchProvider='youtube'  mode='playlist' playlistValue='"+vidID+"']";
    	url: 'http:\/\/\/wp-admin/admin-ajax.php',
            data: {action: 'newVidGallery',
    	success: function(result){

    … And finally functions.php renders the shortcode with do_shortcode() and sends the html back to the page:

    add_action('wp_ajax_newVidGallery', 'newVidGallery_function');
    add_action('wp_ajax_nopriv_newVidGallery', 'newVidGallery_function');
    function newVidGallery_function() {
    	$newVidGalleryPOST = $_POST['newGalleryShortcode'];
        echo do_shortcode($newVidGalleryPOST);	

    At least that’s what’s *supposed* to be happening. What’s going wrong?

    And help is appreciated. ~gyz

Viewing 1 replies (of 1 total)
  • Joy


    It all looks correct, and you are getting a result, so no syntax errors.
    Perhaps tubepress needs more context, like current post?

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.