Support

Account

Home Forums General Issues ACF and Revolution Slider date display

Solved

ACF and Revolution Slider date display

  • Hi – IM using ACF to create a custom field with the date picker. Im then using Revolution slider to display that date. Revolution slider pulls directly from the DB and the date format written by ACF to the DB is YYMMDD.

    I’ve used a ACF update_value hook (below) to reformat the date as its written to the DB.

    it works to modify the value written to the DB but the ACF date picker value does not appear after the the post has been updated, and subsequent updates to the date picker field are not updated in the database.

    any advice would be of a great help.

    // acf/update_value/key={$field_key} - filter for a specific field based on it's name
    add_filter('acf/update_value/key=field_5500bc3920491', 'my_acf_update_value', 10, 3);
    
    function my_acf_update_value( $value, $post_id, $field  )
    {
     	$value = get_field('event_date');
    	$value = date("D F  d", strtotime($value));
        return $value;
    }
    
  • What you are doing is altering the value that ACF needs.

    To alter the value in the database after it is retrieved use this hook: http://www.advancedcustomfields.com/resources/acfload_value/

  • hi guys, im having the same issue with Rev Slider returning YYYYMMDD instead of the format specified in the return format of ACF.

    I cant get anything to work for me, any ideas?

  • Other plugins do not use ACF functions like get_value() to get values stored in the database, they generally use get_post_meta(), a WP function. Because of this there isn’t any way to make ACF convert the format of the stored value into the display format that you want.

    There are a couple of choices. The first is to look into the documentation for rev slider and see if there are any filter hooks available for you to use to alter the display of custom fields. There should be, it is an extensive plugin, and it’s a premium plugin. At any rate, the best information and help for this will come from the rev slider developers or other developers that use it.

    The second choice is to create a new custom field that will hold the date in the format that you want it to be saved in and then use that field in rev slider instead of the acf field.

    
    add_filter('acf/update_value/name=my_date_field', 'store_date_for_other_use', 10, 3);
    function store_date_for_other_use($value, $post_id, $field) {
      // change format to your date format
      $date = date('Y-m-d H:i:s', strtotime($value);
      // use this field meta key in other plugins
      $new_field = 'displayable_date';
      update_post_meta($post_id, $new_field, $date);
    }
    
  • Hi John

    Thanks for all the info, i ended up creating a shortcode the Ess. Grid and Rev Slider plugins.

    function getdatefromacf_shortcode( $atts ) {
    
    	// Attributes
    	extract($atts = shortcode_atts(
    		array(
    			'postid' => '',
    			'metaid' => 'date_from'
    		),
    		$atts
    	));
    
    	return get_field($metaid, $postid);
    }
    add_shortcode( 'getdatefromacf', 'getdatefromacf_shortcode' );

    This in Ess. Grid
    [getdatefromacf metaid='date_from' postid=%post_id%]

    and this in Rev SLider
    [getdatefromacf metaid='date_from' postid={{id}}]

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

The topic ‘ACF and Revolution Slider date display’ is closed to new replies.