• Resolved Konstabel

    (@konstabel)


    I am trying to get the excerpt from my posts.

    In the posts themselves I inserted the <!–more–> tag.

    My code:

    <?php
      $args = array( 'numberposts' => '1' );
      $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
          echo '<h4><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a></h4>';
    
          $excerpt = get_the_excerpt();
          echo $excerpt;
          the_excerpt();
          echo $recent["the_content('Read the rest of this entry »')"];
     }
    ?>

    As you will see I have tried multiple option, but none seems to be working.

    Can anyone please help?

Viewing 1 replies (of 1 total)
  • Thread Starter Konstabel

    (@konstabel)

    I found the problem.

    My search loop was empty. By adding a WP_Query search before I managed to get posts, and then their excerpts.

    The empty query was due to the page address (I am making a custom page).

    <?php $the_query = new WP_Query('define your own query');
        if($the_query->have_posts()):
            while ($the_query->have_posts()): $the_query->the_post();?>
    	    <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                <p><?php the_excerpt(); ?><p>
    	endwhile;
    
    	else:
    	    echo '<p>Nothing found</p>';
    	endif;
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Excerpt not working’ is closed to new replies.