Support » Plugins » Basic PHP variable problem – custom fields

  • I’m trying to separate a list of events (a custom post type) into two sections – upcoming and passed. I figured the best way to do this was to run two separate loops, one under each heading, which compare the custom field date value with the current date, one showing things before the current date, the other after the current date.

    I’ve tried various bits of code to set the variable, but can’t get it to work (I’ve not used variables in PHP before). Could someone point me in the right direction?


Viewing 3 replies - 1 through 3 (of 3 total)
  • What do you have so far?

    Thanks for your reply!

    This is the loop code I have so far, which adds a prefix to each entry depending on its category:

    <?php query_posts('post_type=event&meta_key=date&orderby=meta_value&order=ASC'); ?>
    <?php while (have_posts()) : the_post(); ?>
    	<li style="list-style:none">
             > 	<?php if ( get_post_meta($post->ID, 'book_launch', true) ) : ?>Book Launch: <?php endif; ?>
    		<?php if ( get_post_meta($post->ID, 'book_signing', true) ) : ?>Book Signing: <?php endif; ?>
    		<?php if ( get_post_meta($post->ID, 'media_appearance', true) ) : ?>Media Appearance: <?php endif; ?>
    		<?php if ( get_post_meta($post->ID, 'public_lecture', true) ) : ?>Public Lecture: <?php endif; ?>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>  /  <?php echo get_post_meta($post->ID, 'date', true); ?>
    <?php endwhile; ?>

    The custom field for the date is called ‘date’ (the loop is currently ordered by that) and its output format is currently yy mm dd, for sorting reasons, though this can be changed.



    Scrap that last – this is the code I now have. It pulls the posts but the variable isn’t working. I planned to run this loop twice, once for events before ‘now’ and one for events after ‘now.’

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Basic PHP variable problem – custom fields’ is closed to new replies.