Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Rebecca Jensen
Rebecca Jensen
11,580 Points

New custom post types not appearing (but old ones do)

I made a custom post type called "event" and am populating some of its custom fields to another page (the "all events" page), into a table with the event name, location, etc.

While building this, I got the names of two event posts to appear on the event page. Sweet! Connection is working.

I work on some other stuff, come back to it, and add more event posts. These new posts do not appear in the table. ???

Here is the single-event.php

<?php get_header(); ?>

<div class ="row"> <!-- row for content LEFT -->
  <div class="col-lg-9 col-md-9 col-sm-9 more-pad-right no-pad-left"> <!-- col 9 for content LEFT -->
    <div class="col-lg-12 lg-mrg-bottom no-pad-left"> <!-- inner col 12 for content LEFT -->

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <div class="page-header lg-mrg-bottom">
            <h1><?php the_title(); ?></h1>
            <hr></hr>
            <div class="event-subhead">
                <h3><?php $date = DateTime::createFromFormat('Ymd', get_field('event_date')); echo $date->format('l, F j');?></h3>

            <h3>  
              <?php

                $posts = get_field('map_link');

                if( $posts ) {

                    foreach( $posts as $post ):
                        setup_postdata($post);
                        echo '<a href="' . get_the_permalink() . '">';
                        echo get_the_title();
                    endforeach;
                    wp_reset_postdata();
                }

              ?>
            </h3>


            </div>
        </div>

        <div class="lg-mrg-bottom">
            <h2>COURSE DESCRIPTION</h2>
            <p><?php the_field('course_description'); ?></p>
        </div>

        <div class="lg-mrg-bottom">
            <h2>COURSES</h2>
            <p><?php the_field('courses'); ?></p>
        </div>

        <div class="course-help lg-mrg-bottom">
            <?php the_field('course_help'); ?>
        </div>

        <div class="lg-mrg-bottom">
            <h2>PRICES</h2>
            <p><?php the_field('prices'); ?></p>
        </div>

        <div class="sign-up lg-mrg-bottom">
            <h2>SIGN UP</h2>
            <div class="col-lg-6 xs-mrg-top no-pad-left sm-pad-right">
                <a href="<?php the_field('link_to_registration'); ?>"><button class="btn-lg sm-mrg-bottom">REGISTER</button></a>
                <?php the_field('registration_info'); ?>

            </div>
            <div class="col-lg-6 xs-mrg-top no-pad-left sm-pad-right">
                <a href="<?php the_field('link_to_volunteer'); ?>"><button class="btn-lg vol-btn sm-mrg-bottom">VOLUNTEER</button></a>
                <?php the_field('volunteer_info'); ?>
            </div>
        </div>



    <?php endwhile; endif; ?>


    </div> <!-- close content LEFT col 12 -->
  </div> <!-- close content LEFT col 9 -->


<?php get_sidebar( 'event' ); ?>

</div> <!-- close content LEFT row -->

<?php get_footer(); ?>
<?php
/*
    Template Name: All Events Page
*/
?>

<?php get_header(); ?>

<div class ="row"> 

  <div class="col-lg-12" id="no-pad"> 

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <div class="page-header">
            <h1><?php the_title(); ?></h1>
            <hr></hr>
        </div>

        <?php the_content(); ?>

    <?php endwhile; endif; ?>





<?php
// get posts
$posts = get_posts(array(
    'post_type'     => 'event',
    'meta_key'      => 'event_date',
    'orderby'       => 'meta_value_num',
    'order'         => 'ASC',
    'meta_value'    => date('Ymd'),
    'meta_compare'  => '>=',
        'meta_query'    => array(
            array(
                    'key' => 'date',
                    'value' => date('Ymd'),
                    'compare' => '>=', //Greater than
                    'type' => 'DATETIME'
                )
            ),
    ));
if( $posts ): ?>


    <div>
        <table class="table table-striped">
            <tr id="column-titles">
              <th>DATE</th>
              <th>EVENT PAGE</th>
              <th class="hidden-xs">TERRAIN</th>
              <th class="hidden-xs">MAP</th>
              <th>DIRECTIONS</th>
              <th>HOST</th>
            </tr>
<?php foreach( $posts as $post ):
setup_postdata( $post ) ?>

            <tr class="event">
              <td class="date"><?php $date = DateTime::createFromFormat('Ymd', get_field('event_date')); echo $date->format('D, M j');?></td>
              <td class="event-name"><a href="<?php the_permalink();?>"><?php the_title();?></a></td>
              <td class="terrain hidden-xs">Terrain</td>
              <td class="map-name hidden-xs">Shoreview Community College</td>
              <td class="event-location">Event location</td>
              <td class="club-host-name">COC</td>
            </tr>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>


        </table>
    </div>




  </div> <!-- close col-12 -->

</div><!-- close opening row -->

<?php get_footer(); ?>

Any suggestions?

Thank you!