Skip to:
Content
Pages
Categories
Search
Top
Bottom

"the_content" filter is removed but NOT restored, on custom WP_Query


  • htz77
    Participant

    @tzeldin88

    Hi. My site has a custom WP_Query (outside the main loop) in the header (in header.php), and another in the footer (in footer.php). On all/only my bbPress pages, the paragraph breaks in this content are missing, because wpautop is not applied as it normally is.

    That’s because bbPress REMOVES THE FILTER “the_content”. I tracked it down to bbp_remove_all_filters( ‘the_content’ ); in bbpress/includes/core/theme-compat.php, line 633.

    In that same file, I also see bbp_restore_all_filters(), which looks like it should fix the problem. But it’s not actually working on my custom queries.

    So how can I apply bbp_restore_all_filters() to my custom WP_Query calls?

    Thanks for any help here!

    MY WORDPRESS INFO:
    Wordpress v3.4.2
    bbPress v2.2.1

    RELATED POST:
    I also had a similar issue a month ago (http://bbpress.org/forums/topic/conflict-with-custom-wp_query-in-header-php/) where bbPress conflicted with these same WP_Query calls in my header and footer. But in that case, the main content from bbPress was REPLACING the content from my WP_Query. I somehow solved that problem by just changing my slugs. But I now see it was probably caused by add_filter( ‘the_content’, ‘bbp_replace_the_content’ );, also in this theme-compat.php file.

Viewing 7 replies - 1 through 7 (of 7 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    It’s most likely not because of this. Even here at bbPress.org, the header, sidebar, and footer all create new WP_Query objects without any issues.

    bbPress 2.2 even adds additional checks for is_main_query() and in_the_loop() to make sure this doesn’t happen.


    htz77
    Participant

    @tzeldin88

    Hey JJJ, thanks for helping out again.

    Hmm. When I comment out line 633 in bbpress/includes/core/theme-compat.php,
    //bbp_remove_all_filters( 'the_content' );
    the problem is fixed — the custom WP_Query’s all have the correct paragraph breaks. So it still seems related to me somehow. But of course I don’t want to just keep it commented out. I’m sure it’s there for a reason, and I don’t want to edit core files.

    Also, I just added is_main_query() and in_the_loop() to the templates that do my custom WP_Query queries. And even those show is_main_query = TRUE, which seems weird, huh. Though in_the_loop = False, as it should be, so I’m not sure why that wouldn’t prevent the problem.

    Any further insight much appreciated!


    htz77
    Participant

    @tzeldin88

    Hi JJJ. Another thought on this.

    Even here at bbPress.org, the header, sidebar, and footer all create new WP_Query objects without any issues.

    The header, sidebar, and footer on bbPress.org don’t seem to have any paragraph breaks, so it’s not clear that wpautop() is actually working on them, right?

    I just need to figure out how to add the normal wp content filters — wpautop() and wptexturize() back onto the_content, after bbPress has had its way with it.


    htz77
    Participant

    @tzeldin88

    I found a solution: if my template uses get_the_content() instead of the_content(), then I can apply the normal content filters — wpautop() and wptexturize() — directly to the raw content, untouched by bbPress.
    $raw_content = get_the_content();
    echo wptexturize(wpautop($raw_content));


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    That’s not a great solution, because you’re missing out on all the other things that hook to the_content otherwise.

    Are you using query_posts() anywhere? Are you not using wp_reset_query(); when your WP_Query’s are done?


    htz77
    Participant

    @tzeldin88

    Agreed. I’d prefer to use the_content(). But I don’t know how to get the original filters restored, after bbPress removes them.

    Hi tzeldin88,

    I had a similar problem. I am using various get_post_field calls to display parts of a footer that need to be editable by a client and needed to do apply_filters(‘the_content’,$x).

    I have found that if I call bbp_restore_all_filters('the_content',0);, it will bring the filter back, but it doesn’t affect the rest of the forum. 🙂 I would assume that calling the bbp_remove_all_filters() function after will disable it back.

    Hopefully my example here is clearer.
    http://pastebin.com/BdiMFGTV

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar