• ckemp23

    (@ckemp23)


    I’m trying to display event information in a php-enabled sidebar text widget. The information that is to display includes: (1)Title, (2)Permalink, (3)Date & (4)Location.

    The title and Permalink do display, of course. However, the Date & Location (Custom Fields) do not.

    This is my current code:

    <?php
    $timecutoff = date("Y/m/d");
    $args=array(
    'category_name' => 'events',
    'orderby' => 'meta_value',
    'meta_key' => 'Sortdate',
    'meta_compare' => '>=',
    'meta_value' => $timecutoff,
    'order' => 'ASC',
    'posts_per_page'=>2
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    	?>
         <div class="content">
    	<ul>
    <?php
    while ($my_query->have_posts()): $my_query->the_post();
    $Date = get_post_meta($post->ID, "Date", true);
    $Location = get_post_meta($post->ID, "Location", true);
    ?>
       <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br />
    	<?php echo $Date; ?><br />
    	<?php echo $Location; ?>
    	</li>
      <?php endwhile; ?>
     </ul>
     <br />
    <br />
     <a href="/2j/get-educated/" class="triangle">See All Classes</a>
    
    <?php }
    wp_reset_query();
    ?>

    Where Am I going wrong? Any help would be greatly appreciated. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    try get_the_ID() instead of $post->ID in the get_post_meta() code

    Thread Starter ckemp23

    (@ckemp23)

    That did it – simple error on my part. Thanks so much for your time, Alchymyth!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Fields Nott Displaying in Sidebar Widget’ is closed to new replies.