I would like to find a function that will automatically change a posts date to the modified post date.
I'm using wp User front end plugin so that visitors can add and edit a custom post. I'm also using the Post expirator plugin so that their post will automatically be set to draft after 1 month. The user will then be emailed and asked to update their post for it to go back on line. The problem is that the plugin only sees the post date. So once a user logs back in and edits their post (using front end user) the expirator date isn't reset to be 1 month from the modified date, instead it still uses the original date. Hope that all makes sense. So my choices are to either try and write my own function to handle the post expiration based on the modified date or to try and force the posts date to change to the same as the modified date once it has been updated.
Can anyone help me with either solution? I'm guessing the latter solution would be the most straight forward to implement but willing to head advice.
Many thanks
D
I've tried the suggestions below but have not managed to get this to work. Can anyone offer a solution to this?
Thanks again!
D
I would like to find a function that will automatically change a posts date to the modified post date.
I'm using wp User front end plugin so that visitors can add and edit a custom post. I'm also using the Post expirator plugin so that their post will automatically be set to draft after 1 month. The user will then be emailed and asked to update their post for it to go back on line. The problem is that the plugin only sees the post date. So once a user logs back in and edits their post (using front end user) the expirator date isn't reset to be 1 month from the modified date, instead it still uses the original date. Hope that all makes sense. So my choices are to either try and write my own function to handle the post expiration based on the modified date or to try and force the posts date to change to the same as the modified date once it has been updated.
Can anyone help me with either solution? I'm guessing the latter solution would be the most straight forward to implement but willing to head advice.
Many thanks
D
I've tried the suggestions below but have not managed to get this to work. Can anyone offer a solution to this?
Thanks again!
D
Share Improve this question edited Nov 12, 2013 at 14:16 user36987 asked Nov 7, 2013 at 14:21 user36987user36987 371 gold badge2 silver badges6 bronze badges 1- If you are using dates in your permalinks you will be constantly creating broken links. Be aware. – s_ha_dum Commented Nov 7, 2013 at 14:24
1 Answer
Reset to default 0Doing what you ask is remarkably easy.
function reset_post_date_wpse_121565($data,$postarr) {
// var_dump($data,$postarr); die; // debug
$data['post_date'] = $data['post_modified'];
$data['post_date_gmt'] = $data['post_modified_gmt'];
return $data;
}
add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);
I answer with hesitation though. As in my comment, if you are using dates in your permalinks you will generate broken links every time that post_date
changes.
The real problem in your case seems to be the design of the "expirator" plugin which would mean that the proper solution might be to redesign that plugin, or find a filter that it provides, instead of altering something like the post date (which has consequences).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745040707a4607788.html
评论列表(0条)