The MU forums have moved to WordPress.org

Finding the newlines in post.post_content (5 posts)

  1. westpointer
    Member
    Posted 14 years ago #

    I have a plugin that inserts code into the_content. I'm using explode('</p>', $content) in WordPress to break up $content in paragraph blocks. That's great in WP because before inserting the post into the database, WP replaces the newlines with paragraph tags.

    However, WP mu doesn't do that. The post table still has the newlines instead of the html paragraph tags. What can I use in my explode statement instead of the closing paragraph tag?

    Thanks!

  2. andrea_r
    Moderator
    Posted 14 years ago #

    WPMU strips all kinds of stuff in posts, so not sure if you can sub something else, as it will probably get stripped.

  3. westpointer
    Member
    Posted 14 years ago #

    I'm using an add_filter [add_filter('the_content', 'my_function');] so what I'm doing isn't impacted by what gets stripped. I just can't figure out how to match the returns. I've tried /n/n, \/n\/n, char(10), etc but I'm so far no luck. :-(

  4. cafespain
    Member
    Posted 14 years ago #

    Make sure that your function is called first if you want to get in before WPMU starts auto formatting the content:

    add_filter('the_content', 'my_function', 1);

    then

    explode("\n", $content);

    Make sure you use double quotes. Single quotes will look for the literal value, not the escaped one (newline).

  5. westpointer
    Member
    Posted 14 years ago #

    Thanks! The double quotes solved my problem! I'd been using single quotes around the \n.

About this Topic

  • Started 14 years ago by westpointer
  • Latest reply from westpointer