Support

Account

Home Forums General Issues Date Picker Default Value

Solved

Date Picker Default Value

  • I’m running a query to retrieve all posts that have release dates that are in the future for my “Coming Soon” page. In some cases the date isn’t known and the field is left empty. I’d like to retrieve these posts as well. In order to use a WP meta_query, it seems there needs to be a value set. Is there a way to set the default value for a date picker field – just like you can with a regular text field? The query would look like this:

    $date = date( 'Y/m/d' );
    $args = array(
    	'paged' 	=> $paged,
    	'post_type'     => 'gameboard',
    	'orderby' 	=> 'title',
    	'order' 	=> 'ASC',
    	'meta_key'      => 'gb_release_date',
    	'status' 	=> 'publish',
    	'meta_query'=> array(
    		'relation' => 'OR',
    		array(
    			'key' 	  => 'gb_release_date',
    			'value'   => $date,
    			'type' 	  => 'date',
    			'compare' => '>'
    		),
    		array(//the second part would look something like this
    			'key' 	  => 'gb_release_date',
    			'value'   => 'no_value',
    			'compare' => 'LIKE'
    		)
    	)
    );
    query_posts( $args );

    Any help is appreciated 🙂

  • Just a suggestion, but would it be possible for you to enter hypothetical date for the release of the film but also have a check box field for “To Be Determined”. That way, the entry will still sort in your lists but the date that you insert will be replaced with “To be determined” in the page view?

    <span class="release_date">
      <?php if get_field('tbd'){?>
        To be determined
      <?php }else{ 
        the_field('release_date') };
      ?>
    </span>

    This might only be a duct-tape solution and there is probably a better answer to this, but it should work for the time being.

  • Thanks! Never thought about approaching it that way. That’s what I’ll do for now, however, it would be great have a default date value built into later iterations of the plugin. I suppose I can’t complain…this plugin is a godsend. Thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Date Picker Default Value’ is closed to new replies.