WordPress.org

Ready to get started?Download WordPress

Forums

Getting content with Ajax, [shortcode] content is missing. Any ideas?? (15 posts)

  1. trusktr
    Member
    Posted 3 years ago #

    Hello!

    I'm retrieving content dynamically with AJAX techniques. However, the content that is returned is missing some stuff that is added to the post with [shortcode].

    For example, if I embed a video player in my post by using a shortcode from JW Player Plugin for WordPress, and then try and retrieve that post content via ajax to inject into some other page, then i don't get the embedded player. I can only see the player if I visit the actual post page normally.

    Other plugins like NextGen Gallery, on the other hand, work just fine. NextGen Gallery content comes back with my ajax calls just fine.

    I'm using jQuery kind of like this:
    $(".foobar").load("http://mysite.com/blog-post/", function() { etc, etc... });

    The html that is returned is perfect except for it's missing the embed code that the JW Player Plugin is supposed to inject.

    Anyone know what might be the difference between those two plugins with respect to how they handle shortcodes?

  2. owen.hoskins
    Member
    Posted 2 years ago #

    I am having exactly the same issue! Maybe should address this issue on the longtail forums...

  3. owen.hoskins
    Member
    Posted 2 years ago #

    Just found this post, which seems to explain why jw player shortcodes aren't parsing:

    http://wordpress.stackexchange.com/questions/17639/cannot-strip-jw-player-shortcode

    JW Player Plugin for WordPress does not register its shortcode like all other shortcodes, so strip_shortcodes() will not know about it and not strip it. In the code there is a note that this is because it uses argument names with a . in it, and WordPress does not support this.

    I can't determine how then, if they are registered differently, to get JW Player shortcodes to behave like other shortcodes in ajax calls...

  4. owen.hoskins
    Member
    Posted 2 years ago #

    and this post shows that the plugin has been updated to accommodate shortcodes in widgets: http://wordpress.org/support/topic/plugin-jw-player-plugin-for-wordpress-insert-jw-player-plugin-into-a-widget

  5. JW Player
    Member
    Posted 2 years ago #

    Hey Guys,

    Instead of do_shortcode you would need to use apply_filters(http://codex.wordpress.org/Function_Reference/apply_filters).

    Hope this helps.

  6. owen.hoskins
    Member
    Posted 2 years ago #

    Hey, thanks for the reply.

    What I don't understand is why its only in ajax calls that the jw player shortcode doesn't parse?

    <?php
    $shortcode = do_shortcode('[jwplayer]');
    echo apply_filters('the_content', $shortcode);
    ?>

    You're saying that the above isn't the right approach... as do_shortcode has already been called on the_content?

    What part of the process do I need to address? Modify the plugin? functions.php? page template? my javascriot call? I am not well versed in apply_filter so I am at a loss as how to proceed.

    Anyhow, I expect this is a common issue and probably should be documented properly within the plugin.

    Thanks for the help.

  7. tasty.donuts
    Member
    Posted 2 years ago #

    apply_filters is used in the functions.php.

    http://codex.wordpress.org/Function_Reference/apply_filters

  8. owen.hoskins
    Member
    Posted 2 years ago #

    That's a start, but what $tag and what $value are we working with here?

  9. JW Player
    Member
    Posted 2 years ago #

    @owen.hoskins

    $tag is the name of the filter which in this case is 'jwplayer_tag_callback'. The $value is 'the_content' since you want to run it on the post body. So ultimately your you would want to do something like the following:

    <?php
    echo apply_filters('jwplayer_tag_callback', 'the_content');
    ?>

    This should echo out the embed code which will actually insert a JW Player.

  10. owen.hoskins
    Member
    Posted 2 years ago #

    @LongTail Video, thanks again for the reply:

    in functions.php:

    function jwplayer_ajax() {
    	echo apply_filters('jwplayer_tag_callback', 'the_content');
    }

    in my template file:
    <?php jwplayer_ajax(); ?>

    only prints the text 'the_content', as if it interpreted the value as a text string.

    So I tried:

    function jwplayer_ajax() {
    	$content = get_the_content();
    	echo apply_filters('jwplayer_tag_callback', $content);
    }

    Which returned the unformatted content including the shortcode as text [jwplayer playlistid="16"]

    And finally:

    function jwplayer_ajax() {
    	$content = the_content();
    	echo apply_filters('jwplayer_tag_callback', $content);
    }

    Which returned the formatted content without the shortcode...

    I feel as if we're on the right track but missing some important step...?

    Thanks again!

  11. JW Player
    Member
    Posted 2 years ago #

    @owen.hoskins,

    What happens if you just echo the_content()? I believe this is supposed to apply all of the the_content filters anyways so manually applying the jwplayer_tag_callback is likely unnecessary.

    When you say the shortcode is gone what are you seeing?

    Thanks.

  12. owen.hoskins
    Member
    Posted 2 years ago #

    @LongTail Video,

    echoing the_content() produces no difference then simply using the_content(), not sure why it would be any different anyhow, since the_content ignores the jwplayer shortcode when loaded via ajax.

    and, by the "shortcode is gone", I mean that when I would use get_the_content() it would return the [jwplayer] shortcode as raw text, where as the_content() does not even return the [jwplayer] as raw text, just nothing.

    I've been playing with this on my local machine, I think today I'll put a test version online to illustrate the problem.

    Thanks for the help!

  13. owen.hoskins
    Member
    Posted 2 years ago #

    @LongTail Video,

    The test page I promised earlier today:

    Test page

    This is using the standard <?php the_content(); ?>, which returns everything but the desired JW Player. The ajax call is loading the exact same content that is displayed correctly above it.

    Would you help me get this test page to work?

    Thanks!

  14. owen.hoskins
    Member
    Posted 2 years ago #

    Taking the test page posted above offline and trying a different approach as this seemingly simple issue has no resolution.

  15. JW Player
    Member
    Posted 2 years ago #

    @owen

    I apologize for not being able to look at your test page. I've been out sick for quite a while and have been swamped catching up on various other projects.

    If you put the page back up I will take a look. It seems to be up in some form currently however the Ajax call is failing.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic