WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just transformed my query_posts function in a get_posts function.

Here is my old function:

// The Query
query_posts( 'cat=170&showposts=4' );
remove_filter('the_excerpt', 'wpautop');
// The Loop
while ( have_posts() ) : the_post();
    echo '<h3 style="font-size:14px"><a href="';the_permalink(); echo '" title="';the_title(); echo '"> '; the_title(); echo '</a></h3> <div class="ultimipostexcerpt">'; the_excerpt(); echo '</div>';
// Reset Query

Here's my new one

$args = array( 'posts_per_page' => 4, 'category' => 170 );
$tag_posts = get_posts( $args );
    foreach ( $tag_posts as $post ) :
      setup_postdata( $post ); ?>
        <h3 style="font-size:14px"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3><div class="ultimipostexcerpt"><?php the_excerpt(); ?></div>
    <?php endforeach;
    wp_reset_postdata(); ?>

The problem is that now the remove_filter('the_excerpt', 'wpautop'); directive doesn't work anymore.. I tried putting it before and after get_posts( $args );, doesn't affect the output.. :( how can I remove the filter for get_posts too?

share|improve this question

You could make your own excerpt function:

    function wpse125086_custom_strip_tags_excerpt() {
        global $post;
        $p_obj = get_post($post->ID);
        $p_exp = $p_obj->post_excerpt;
        $p_exp = apply_filters('the_excerpt', $p_exp);
        $un_p = array("<p>", "</p>");
        $p_exp = str_replace($un_p, "", $p_exp);
        echo $pcont;

But generally I'm thinking instead of transforming to get_posts() it might be better to go with WP_Query. In this case the standard filter you're using should work just fine.


If it's about the opening/closing <p></p> tags, you can just go with get_the_excerpt(), because it doesn't add those. you have to echo it to print the excerpt out.

echo get_the_excerpt();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.