Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TC.K

    (@wp_dummy)

    By default it is not supported by this plugin. Date field is complicated. It’s many limitation. If you want have a date field for filter, your date field must store as YYYY-MM-DD format.

    If the format is correct, then in processing the query, you will have to insert correct meta field in meta query by this uwpqsf_get_cmf filter.

    Thread Starter nanny7

    (@nanny7)

    Hi the custom fields is YYYYMMDD and I convert it – this is my query:

    
    $today = date('Ymd');
    $args = array(
    'post_type' => 'events',
    'post_status' => 'publish',
    'posts_per_page' => '-1',
    'meta_query' => array(
            array(
                'key' => 'dates',
                'compare' => '>=', // Upcoming Events - Greater than or equal to today
                'value' => $today,
            )
        ),
        'meta_key' => 'dates',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',
        );
    
    

    With the filter you gave me how do I use it and do I use all of it or just part of it?

    Plugin Author TC.K

    (@wp_dummy)

    You can try this:

    add_filter('uwpqsf_get_cmf', 'add_customdate_get','',3);
    function add_customdate_get( $cmf,$id, $getcmf ){
           $i = 0;
    	foreach($getcmf as  $v){
    		if(!empty($v['value'])){
    			if($v['compare'] == '>='){
                                   //if you want to applied to specific meta field only
                                   if($v['metakey'] == 'your_desired_metafield'){
                                    $cmf[$i] = array();//just to make sure no duplicate meta field in the query.
    				
    				$cmf[] = array(
    					'key' => strip_tags( stripslashes($v['metakey'])),
    					'value' => $v['value'],
    					'type' => 'DATE',
    					'compare' => '>='
    					);
    			          }
    			}
    		 }
             $i++;
           }
    	  return $cmf;
     }	

    Note, the codes is not tested. It may not works, it’s just shows you the idea

    Thread Starter nanny7

    (@nanny7)

    Hi thanks how will that work with the datepicker field?
    Is there any way to get an options like you had in https://s.w.org/plugins/ajax-wp-query-search-filter/screenshot-3.png?r=1513692

    where you can use the date field and add the month name and year name as a drop down.

    Thread Starter nanny7

    (@nanny7)

    Hi I am back again to try again, I came across this link and not sure if it would work to get a drop down of the date field dates into months:https://wordpress.stackexchange.com/questions/113419/custom-filtering-on-month-value-only-of-an-entire-date-field

    this is what they used: -01-::Jan|-02::Feb|-03-::Mar|-04-::Apr|-05-::May|-06-::Jun|-07-::Jul|-08-::Aug|-09-::Sep|-10-::Oct|-11-::Nov|-12-::Dec

    I still can’t see how that will filter, but is this on the right track?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add a dropdown of custom field dates months’ is closed to new replies.