Skip to:
Content
Pages
Categories
Search
Top
Bottom

Conflict with custom WP_Query in header.php


  • tzeldin88
    Participant

    @tzeldin88

    I have a custom WP_Query outside the main loop, in my header.php, and also another one in footer.php. On my Forums List page (the top/base level of bbPress that lists all my Forums), the custom WP_Query in both header.php and footer.php, no longer works. It shows another instance of the bbPress Forums List, instead of showing the correct content (as it does on every other page of my site, including all other bbPress pages). My custom WP_Query is
    $args = array(
    'post_type' => 'page',
    'page_id' => 218
    );
    $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();

    the_content();
    endwhile;
    wp_reset_postdata();

    I also tried get_page, which also didn’t work.
    $page_id = 218;
    $page_data = get_page( $page_id );
    $page_content = apply_filters('the_content', $page_data->post_content);
    echo $page_content;

    I tried using a bbPress ShortCode in a WP-Page called “Forums”, and then also without a page, just using bbPress Permalink “Forums”, without a wp-page and shortcode. Same problem either way.

    Why would bbPress conflict with these core WP functions? And why would it happen ONLY on the Forums List page? I also tested this in TwentyEleven, and the problem is there too.

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

  • Shane Gowland
    Participant

    @thewebatom

    Have you tried setting the_query objects to null after each loop?


    Shane Gowland
    Participant

    @thewebatom

    Sorry, ignore what I’ve written. I read this completely wrong.

    (although it’s actually not a bad idea to reset WP_Query objects after their usefulness expires. wp_reset_query() is the better way of doing it, but all that does is call wp_reset_postdata, so my point is moot.)


    tzeldin88
    Participant

    @tzeldin88

    @Shane – Hey, thanks for responding, i appreciate the help. I finally found the issue. It was a conflict with the Slug i had entered in WP-Admin > Settings > Forums > Archive Slugs > Forums Base. I had it as “forums” — i guess that’s the same name as the CPT used by bbPress. So when i changed my slug to “theforum”, the problem was solved.

    • This reply was modified 1 year, 10 months ago by  tzeldin88.
Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.