the_excerpt & the_content

This topic contains 2 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10353

    I posted this over in pre-sales but went ahead and purchased to get an answer. I’ve written a custom loop (once using eo_get_events and another using wp_query). In both instances I am unable to use the_excerpt or the_content to display the events content. Oddly enough echo get_the_content() works just fine in both loops, but echo get_the_excerpt() does not. I have Excerpts checked in settings as a supported feature for Events.

    I have no idea how the_content would not work but echo get_the_content would. Any ideas on why this would be happening? I’ve tried it on two separate wordpress installations (one local, one on a server)

    <?php
    //Get upcoming
    $args = array(
        'numberposts'=>3,
        'event_start_after'=>'today',
        'showpastevents'=>true,
        'post_type'=>'event',
        'suppress_filters'=>false
    );
    $eventloop = new WP_Query( $args );
        if ( $eventloop->have_posts() ) :?>
        
      <?php while ( $eventloop->have_posts() ) : $eventloop->the_post(); ?>
    • '> <h5><?php the_title(); ?></h5> on <?php eo_the_start('jS F Y'); ?>

      <?php the_excerpt(); ?>

    • <?php endwhile; wp_reset_postdata(); ?>
    <?php else : echo 'No Upcoming Events'; endif; ?>
    Josh Rives
    #10354

    Nevermind…I figured it out. It was another custom function not this plugin. Thanks

    Josh Rives
    #10355

    Hi Josh,

    eo_get_events() – is a bit like get_posts() in that functions like the_content(), won’t work (without a little bit of a work-around).

    However, it should work fine with WP_Query() and $eventloop->the_post(). It’s also really odd behaviour that echo get_the_content() works but the_content() doesn’t. Looking at the source you’ll see that the_content() just uses get_the_content() and applies a filter to it. So typically they’ll work or fail together.

    That the_content() isn’t working, points to a plug-in or theme doing something on the_content filter ( probably that is changing the global $post). Testing (code below) on a ‘blank’ (almost) install, I don’t get any issues. So it suggests it’s probably another plug-in or theme responsible. I’d recommend disabling all other themes/plugins to see if the issue persists (and if not, which plugin/theme was responsible).

    Also, where have you used this code? Context may also play a role (I placed the test code below in TwentyThirteen’s header.php.)

    Test code:

    <?php
        $args = array(
            'numberposts'=>3,
            'event_start_after'=>'today',
            'showpastevents'=>true,
            'post_type'=>'event',
            'suppress_filters'=>false
    );
        $eventloop = new WP_Query( $args );
        if ( $eventloop->have_posts() ) :
                while ( $eventloop->have_posts() ) : $eventloop->the_post();?>
    
                <h5><?php the_title(); ?></h5> on <?php eo_the_start('jS F Y'); ?>
    
                <hr>        
                <h6> Excerpt </h6>
                <?php the_excerpt(); ?>
    
                <hr>
                <h6> Echo (get the) content </h6>
                <?php echo get_the_content(); ?>
    
                <hr>
                <h6> The content </h6>
                <?php the_content(); ?>
                <hr>
    
               <?php endwhile; ?>
            <?php   wp_reset_postdata(); ?>
    
    <?php
        else :
            echo 'No Upcoming Events';
        endif;
    ?>
    Stephen Harris
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.