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.