Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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 '11 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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