Yes, what you enter, but copied from the text tab so all the HTML is included. What I’m really after is what is in the post_content field of the DB, but I can’t easily explain how to get to that. The text tab is usually the same thing.
Yes, the preg_match()
line is what you need to edit, then the description will be in $matches
somewhere. Regexps (the ><\/*><
stuff) are certainly mind boggling to the uninitiated. I myself am still not that confident with them.
FYI, for any part of the regexp string that is in parenthesis, and where a segment of the content matches the contained regexp fragment, that matched segment gets assigned to the next available element of $matches
. Right now the first two parenthesis groups match the img and linked img tags, so they are assigned to $matches[1]
and $matches[2]
. Similar for the ul tags.
The .*
portions between parenthesis groups match anything but are not assigned to $matches
. But, for example, if your description occurs after the linked image tag tag and nothing else occurs until the first ul group, changing the current .*
to (.*)
would match your description and add it as $matches[3]
. The subsequent ul matches move from 3 and 4, to 4 and 5.
If the description cannot easily be separated from other text, you may need to place it in an ol block or similar. the ol tags are easily stripped out again if they do not normally occur anywhere, making finding them unambiguous. The delimiting tags do not even need to be valid HTML since they are stripped out, though be wary of the WP content filters.
Another thing that really helps is a regexp fiddle tool. Perhaps with the above info and this tool, you can figure this out on your own. The above tool does not accept the ‘s’ flag (the final ‘s’ in your regexp), so you’ll need to remove any newline chars from your sample to simulate the ‘s’ flag. Hover over the matched portion to see how the sub-matches are assigned. If you still can’t figure this out, go ahead and post the raw text and I’ll try to help you out.
I’m wondering if this sort of setup is really the best approach for you. On one hand, it’s fine as long as it works, and if you have a lot of data configured this way already, it may not be worth converting. (but possible with a custom script) I can see doing the images this way because of the media manager tool.
I would have suggested the UL lists and the description be managed as custom fields (or even a metabox) instead of placing them as part of the content. Matching HTML tags like you are doing is rather fragile. If someone should forget some crucial part of the structured content, the entire thing falls apart. By placing the various parts in dedicated fields, they are no longer interdependent and any input errors are limited to the error itself, not affecting other elements.
The custom fields serve as sort of a reminder of what data is needed, and the specifics of where and how the text is marked up can be relegated to the template instead of it being required to make the whole thing work.
This is just a suggestion of course, there is no need for you to consider this if you do not want to or if it’s too much bother. When I see what I think is a better way to do something, I have trouble not saying anything. I also have no trouble having my ideas ignored if they are not liked. It’s your site after all, not mine ??