• Resolved secondsky100

    (@secondsky100)


    I have a small problem in conjunction with pods magic tags + function + ajax loading by a third party plugin.

    I calculate the age of a person using a date field.
    The function, loaded by Snippet plugin:

    function return_age($input_date) {
    	$now = date("Y-m-d");
    	return date_diff(date_create($input_date), date_create($now))->format('%y');
    }

    The shortcode/magic tag:
    [pods]{@birthday_mod,return_age}[/pods]

    Its a listing which shows the age, city, country and other pods field.
    The other pods fields load normal. Only the field manipulated by the function shows this message if filtered/loaded by a third party plugin: “Please provide a Pod name”. The 3rd party plugin also provides page reloading, in that case the problem does not occur.

    Any idea why this happens or even better, any idea for a solution?

    Thx in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    In that case the Shortcode doesn’t know what data to load since you do not pass any information to the shortcode.
    On initial load (and if it’s inside the loop) it will fallback to the current post, but when using AJAX this might indeed not work.
    You could try to add the use_current parameter.
    Cheers, Jory

    Thread Starter secondsky100

    (@secondsky100)

    Thx for your reply. use_current in shortcode doesnt work unfortunately.

    I thought now to do something else but have no clue how to do that.
    I would like instead of just manipulating the field output to take the birthday and write it into another field but calculated as age.
    I would probably need to do some cron or so to keep that field updated.
    But for now the question is how i would do that with pods.
    Any clue? Code example would be appreciated ??

    With ACF i could do this, but how with pods?

    function my_acf_save_post($post_id)
    {
        // check if post type is model
        $post_type = get_post_type($post_id);
        if ($post_type != 'model') {
            //return if its not a model post type
            return;
        }
        // get year of birth value
     	$year_of_birth = get_field('birthday_model', $post_id);
    	
        //calculate the value of age
    	$now = date("Y-m-d");
    	$age = date_diff(date_create($year_of_birth), date_create($now))->format('%y');
    
        // update the age field
        update_field('age_model_acf', $age);
    }
    
    // run after ACF saves the $_POST['acf'] data
    	add_action('acf/save_post', 'my_acf_save_post', 20);
    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing here in favor of GitHub:
    https://github.com/pods-framework/pods/issues/5566

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Magic Tag, field manipulation with function, doesnt work when using Ajax’ is closed to new replies.