• So I think I keep getting close, but I really suck at these wordpress loops so far.

    I have a custom post type (workshops) and that has a custom field (date). I have been able to query the custom type and display it in order of Workshop – Date, but I don’t want it to show dates that have already passed.
    I used the “Types” plugin in order to create the custom Types and Fields, so “types_render_field(“date”, array(“output”=>”raw”))” is just that plugin spitting out a Unix Timestamp for the Workshop – Date.

    How can I tweak this so the query does not show posts that have a “date” value larger than today?

    Thank you for your help!

    <?php
    	$today = $local_timestamp = get_the_time('U');
    	$args = array(
    		'posts_per_page' => 100,
    		'post_type' => 'workshop-date',
    		'orderby' => types_render_field("date", array("output"=>"raw")),
    		'order' => 'ASC'
    		);
    	query_posts($args);
    	if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		(Post Layout here)
    
    	<?php endwhile; else: ?>
    
    		<p>There are no dates to display.</p>
    
    	<?php endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • // If the stored UNIX timestamp is after current UNIX timestamp
    if( time() < types_render_field( "date", array( "output" => "raw" ) ) )
      {
        // Do stuff
      }

    Maybe I misread the question a little. I’m not sure about the Types and Fields plugin, but if it uses WordPress’ custom fields and just beautifies them in some way, you may want to try these $args:

    $args = array(
    		'posts_per_page' => 100,
    		'post_type' => 'workshop-date',
                    'meta_key' => 'date', // Assumes date is key of the custom field
                    'meta_value_num' => time(),
                    'meta_compare' => '>=',
    		'orderby' => types_render_field("date", array("output"=>"raw")),
    		'order' => 'ASC'
    		);

    Thread Starter theamazingaustin

    (@theamazingaustin)

    Beautiful, thank you so much!

    Thread Starter theamazingaustin

    (@theamazingaustin)

    So I’ve noticed after adding several dates to the “workshop-date” custom post type, the dates are not displayed in order. They are not in their default order, but they are all jumbled up, more or less going from most recent / upcoming to further in the future, but the dates are pretty sporadic.
    see here: https://www.directdevelopmenttraining.com/workshops/workshop-dates/

    Perhaps the “Types” plugin isn’t a suitable mean of sorting? I’ve tried everything I can think of to get it to work… I don’t understand why random dates appear out of order.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I only display posts that have a custom field greater than a variable?’ is closed to new replies.