Support

Account

Home Forums Front-end Issues Front End Form -> the_modified_time()

Solved

Front End Form -> the_modified_time()

    • phil.m

    • August 22, 2013 at 3:47 am

    Hey I’m trying to figure out how to update the modified time on a post when a form is submitted from the front end.

    Basically I’m trying to attach a function to update the post once the form is submitted using the save_post action. It seems like the action is not being attached when the submit button is clicked. If I just call the update_time() function on page load it updates the time properly but I can’t figure out how to attach it so it runs when the front end form is submitted.

    
    <?php
    function update_time() {
      $my_post = array();
      $my_post['ID'] = 1674;
      wp_update_post( $my_post );
    }
    
    add_action( 'acf/save_post', 'update_time');
    
    $options = array(
       'post_id' => 1674
    );
    
    acf_form($options);
    
    ?>	
    

    Is there anyone out there that might know what’s wrong? THANKS =D.

    • Elliot

    • August 22, 2013 at 2:34 pm

    Hi @phil.m

    Looking at your code, there is no reference of editing the time…

    Your update_time function simply does nothing…

    Have you forgotten some code of intentionally left it out?

    • phil.m

    • August 22, 2013 at 10:54 pm

    Hey thanks for replying man.

    The function essentially does do nothing other than update the post object.

    So instead of creating a function that updates the modified time row in the database, I’m using wp_post_update() to simply update the post object so wordpress stamps the new time.

    So if I call this function on page load

    function update_time() {
      $my_post = array();
      $my_post['ID'] = 1674; //or $post->ID in the loop
      wp_update_post( $my_post );
    }
    update_time();
    

    the function runs and updates the post specified (in this case post id 1674) and wordpress updates the last modified time of the post.

    http://codex.wordpress.org/Function_Reference/wp_update_post they show an example of attaching this to save_post, which is basically what I’m trying to do.

    I’ll just manually make the form since I’m only updating 2 meta values (and both of them are pre-populated select boxes lol).

    I’ll mark it as solved but it would be interesting to know if its possible to do this.

    thanks again

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.