Support » Plugin: Ajax Search Lite » Format date in results

  • Resolved Valdinia

    (@valdinia)


    On Settings, Advanced Options, you can set the “Description Field” to be a specific Custom Field. I selected a custom field of type DATE.

    On the UI when I type on the search box the results contain the custom post title and the date as expected, but the date is not formatted (19801211). How could we format it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi!

    The only way of doing that is by using a custom code to get the custom field, instead of that option.

    Try this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_action('asl_results', 'asl_get_date_filed_formatted');
    function asl_get_date_filed_formatted($results) {
    	$field = 'date_field'; // Enter the date field name here
    	
    	// ---- DO NOT EDIT BELOW ----
    	foreach ($results as $k => &$r) {
    		$mykey_values = get_post_custom_values($field, $r->id);
    		if ( isset($mykey_values[0]) ) {
    			$ret = date_i18n( get_option( 'date_format' ), strtotime( $mykey_values[0] ) );
    			$r->content = $ret;
    		}
    	}
    	
    	return $results;
    }

    Change the $field variable value on line 3 to the custom field name that contains the date information.

    Best regards,
    Ernest M.

    Thread Starter Valdinia

    (@valdinia)

    Thank you so much for your help Ernest!

    Valdinia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Format date in results’ is closed to new replies.