Home Forums Add-ons Options Page Options page re-direct on publish


Options page re-direct on publish

  • Is it possible to redirect the user to a specified URL (the homepage) when they publish changes to an ACF options page? I have a function in place that returns them to whatever post they publish changes to, but would be nice to send them to the homepage after publishing on any ACF options page.

    This is what I have for the posts:

    add_filter('redirect_post_location', function($location) {
    	global $post;
    	if (
      	(isset($_POST['publish']) || isset($_POST['save'])) &&
      	preg_match("/post=([0-9]*)/", $location, $match) &&
      	$post &&
      	$post->ID == $match[1] &&
      	(isset($_POST['publish']) || $post->post_status == 'publish') && // Publishing draft or updating published post
      	$pl = get_permalink($post->ID)
    	) {
      	// Always redirect to the post
      	$location = $pl;
     return $location;
  • These forums are hoppin! 😐

  • I don’t think what you’re attempting to do is possible, but I don’t know. Not knowing is probably why no one has stepped up to try to help. As far as I know, there is nothing during save process that will tell you what options page is being submitted.

    I suppose that you could use an acd/save_post action. In your filer you could check to see if the post_id value is ‘options’ and if it is then check to see if one of the fields of a particular options page has been updated and if it has then do the redirect.

  • Hi John,

    I’m not trying to do it on a per options page basis, but rather for all options pages. I don’t know if the options pages is considered a custom post type of sorts where I would be able to set that custom post type to redirect to the home page on save.

  • No, it’s not a post type. Options pages in ACF work the same way that any other custom admin page works.

    The only way to know if these are updated is using an acf/save_post filter with a priority of 20 and check to see if the post ID passed to the filter is “options”

  • Ok, cool. Would the acf/save_post filter only affect option pages? Or will it do all post types? Ideally I’m looking to have any post type (pages, posts, etc) that are not acf option pages to just re-direct on publish back to the post ID (which is what I have above) and the acf option pages to simply just redirect back to the home url.

  • it is called after anything is saved by ACF. That’s why you need to check the post id in your filter to make sure it’s an options page being saved.

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

You must be logged in to reply to this topic.