0

I have a site where a user can insert slideshows into a post by entering the shortcode in the content box. He can also add videos by adding the video code in the same box. I need to separate these two shortcodes out from each other so that I can control when the slideshows are displayed and when the videos are displayed. I'm using add_filter and preg_match to match the correct shortcode and then echo each match out - however it's currently only displaying the first match from each one. Here's my code - I'm not sure I completely understand how add_filter works, so probably have my display methods wrong:

Videos:

/* VIDEO SLICE */
function video_slice( $content ){
    preg_match( '/\[video.*\]/' , $content , $matches );
    if( isset( $matches ) && $matches !== "" ){
        foreach( $matches as $match ){
            return $match;
        }
    }
}

if( !has_filter('the_content') ){
  add_filter( 'the_content','video_slice');   
}else{
  remove_filter('the_content','slidedeck_slice');
  add_filter( 'the_content', 'video_slice');  
}
the_content();

I have a similar setup for the Slideshows, except my slideshow_slice function matches [SlideDeck .*] instead. How can I loop through an array of matches and print the output via the_content()?

Thanks

1 Answer 1

0

If you don't want normal shortcode mechanics (seems like it to me from your description) why bother adding them to content at all?

Create couple of specialized meta boxes and you won't have to deal with scanning and filters at all, just store/retrieve info that you need separately to/from custom fields.

1
  • Yea, the method I used eventually was just to order items in the_content box rather than splitting them through several meta boxes. I think the other problem with the above was I needed to use preg_match_all().
    – lowe_22
    Sep 19, 2011 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.