• I have created a custom taxonomy called Occasions, and I have added custom fields including “holiday_date.”

    I want to be able to return Occasions that are “current” based on today’s date. I have tried a few different methods, but WP doesn’t seem to acknowledge my meta data request. I can’t figure out what I’m doing wrong.

    Here are the two methods I have tried.

    This one comes back empty/null

    $meta_args['meta_query'] = array(
    				array(
    					'key' => 'merch_start_date',
    					'value' => $today,
    					'type'	=> 'DATE',
    					'compare' => '<='
    				),
    				array(
    					'key' => 'holiday_date',
    					'value' => $today,
    					'type'	=> 'DATE',
    					'compare' => '<='
    				)
    			);
    
    		$meta_query = new WP_Meta_Query( $meta_query_args );

    And this one ignores the meta_query entirely…

    $args = array(
            'orderby'       => 'name',
            'order'         => 'ASC',
            'hide_empty'    => true,
            'exclude'       => array(),
            'exclude_tree'  => array(),
            'include'       => array(),
            'number'        => '',
            'fields'        => 'all',
            'slug'          => '',
            'parent'         => 0,
            'hierarchical'  => true,
            'child_of'      => 0,
            'get'           => '',
            'name__like'    => '',
            'pad_counts'    => false,
            'offset'        => '',
            'search'        => '',
            'cache_domain'  => 'core'
        ); 
    
       $args['meta_query'] = array(
    				array(
    					'key' => 'merch_start_date',
    					'value' => $today,
    					'type'	=> 'DATE',
    					'compare' => '<='
    				),
    				array(
    					'key' => 'holiday_date',
    					'value' => $today,
    					'type'	=> 'DATE',
    					'compare' => '<='
    				)
    			);
    
    	$taxonomy_subs = get_terms( $taxonomy, $args );

    https://www.ads-software.com/plugins/ultimate-cms/

  • The topic ‘Accessing the Custom Fields on Custom Taxonomies’ is closed to new replies.