• Resolved guerrilladigital

    (@guerrilladigital)


    WordPress 4.9.9
    ACF PRO 5 v5.7.13

    So far, the plugin works pretty great. It’s updating back and forth between two custom post types, an ACF Relationship field with the same name of ‘related_post’

    When I try to employ the my_overwrite_settings() example function, it doesn’t delete the previous post. On one side of the transaction is essential a “blog post CPT*”, which has a one-to-one relationship with another “blog author CPT”. On the flipside, a “blog author CPT” will have a one-to-many relationship with the “blog post CPT”.

    Is there something inherent in the fact that one side can only have one post relationship, while the other side can have many relationships? Is that why it’s not deleting the first “blog author CPT” if a new one is attached?

    Other than that, this plugin seems to be working pretty great.

    This is the code I’m using in my functions.php file.

    add_filter('acf-post2post/overwrite-settings', 'my_overwrite_settings');
    function my_overwrite_settings($settings) {
      $settings['related_post'] = array(
    	  'overwrite' => true,
    	  'type' => 'first'
    	);
    	return $settings;
    }

    (*note: CPT is shorthand for Custom Post Type, for brevity.)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Huebner

    (@hube2)

    I will have to check on this.

    Plugin Author John Huebner

    (@hube2)

    I just tested this and it is working correctly for me.
    This is what I did.

    I added a relationship fields on “Post” allows multiple selections
    I added a post object field on “Page” that allows 1 selection
    Both fields are named “relationship”
    I added this code to my functions.php file

    
    add_filter('acf-post2post/overwrite-settings', 'my_overwrite_settings');
    function my_overwrite_settings($settings) {
      $settings['relationship'] = array(
        'overwrite' => true,
        'type' => 'first'
      );
      return $settings;
    }
    

    I added a page named “Page 1”, saved
    I added a post named “Post 1” and I selected “Page 1” in the relationship field and saved it
    I reloaded “Page 1” and “Post 1” was set in the post object field
    I then added a post named “Post 2” and I selected “Page 1” in the relationship field and saved it
    I reloaded “Page 1” and “Post 2” was set in the post object field
    I reloaded “Post 1” and “Page 1” was removed from the relationship field.

    I am assuming you have the same field names and that they are both at the top level of the field group since you said it was working other than this.

    Check your code to make sure you have the same field name and that this field name is what you’re setting in your filter. I actually thought it wasn’t working at firsts because I had a typo when I added the code… it happens.

    Do not try to work on and save multiple pages at one time. In the case I mentioned above, If I tried to update a page or post instead of reloading it, the result of the relationships will be based on the last page/post save and what is selected in the relationship/post object field, overwriting anything previously saved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘my_overwrite_settings function example not working’ is closed to new replies.