Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin that filters a particular page, and another plugin(a widget actually) that uses WP_Query to display a number of posts list. The problem is when I am on that particular page that is filtered, the widget that displays a list of posts, gets affected, and displays the content of that filtered page. So I get bunch of cloned contents all over the page, in the content area and in the sidebar(where the widgets reside). How do I filter the the_content so this won't happen, or make the widget so it will function as expected?

the filter code:

add_filter('the_content', 'content');
function content($content) {
    return $content . get_custom_content();
}

the query code:

$second_query = new WP_Query( array(
                        'post_type' => "$post_type",
                        'post_status' => 'publish'
                    ) ); 
// The Loop
if ($second_query->have_posts()) :
    while( $second_query->have_posts() ) : $second_query->the_post();
        $content .= '<span class="permalink"><a href="' .get_permalink(). '">' . get_the_title($post->ID) . '</a></span>';
        $content .= '<p>' . get_the_excerpt() . '</p>';
    endwhile; else :
          $content = '<p>No ' . $options['post_type'] . 's found.</p>';
endif;
wp_reset_postdata();

$title = "<h3>" . $options['title'] . "</h3>";   
echo $before_widget.$title.$content.$after_widget;

SOLUTION:

So came to a conclusion that it's a known issue with the_content messing up with WP_Query. It's discussed here: http://core.trac.wordpress.org/ticket/18561#comment:48

My solution is I installed a filter in the template and filter it instead of the 'the_content':

$below_post_content = '';
echo apply_filters('custom_filter', $below_post_content);

Note that action hook won't work in this case. I don't know why.

share|improve this question
2  
This question is unclear, and nearly impossible to answer, without seeing actual code. – Chip Bennett Oct 21 '11 at 14:26
I second that, and the name/version of the plugin would be great to know of. – soulseekah Oct 21 '11 at 14:29
1  
just updated my post. thanks! – jilseego Oct 21 '11 at 14:40

closed as too localized by toscho Dec 18 '12 at 23:58

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.