Forum Replies Created

Viewing 15 replies - 61 through 75 (of 564 total)
  • Thread Starter John Huebner

    (@hube2)

    After further investigation. I was just looking at the plugin and this plugin depends on the elementor/frontend/section/should_render hook. My understanding of this hook is that it completely removes the content from the page rendering on the PHP side. To my understanding this means that the page would be cached based on the visitor viewing the page when it was cached.

    Please correct me if I am wrong.

    Plugin Author John Huebner

    (@hube2)

    This is working as expected.

    There is no mechanism in ACF to give a “warning” or “message” that the field on the other end will not be updated without returning an error for the field that will prevent the post from being saved. Let me know if you need me to expand on this.

    Preventing a post from being saved is not something that I would want to do because there would be people on the other side of the coin that would not want this. I have made the decision to ignore the update if it breaks the rules on the other end of the relationship and leave it up to the individual developer to alter this to allow overwriting the value on the other end.

    Something like this is left up do the developer using this plugin. Using the acf/validate_value filter provided by ACF this can be accomplished.

    For example:

    
    // this code has not been tested
    add_filter('acf/validate_value/type=post_object', 'validate_bidirectional_relationships', 20, 4);
    add_filter('acf/validate_value/type=relationship', 'validate_bidirectional_relationships', 20, 4);
    function validate_bidirectional_relationships($valid, $value, $field, $input) {
      global $post;
      if (!$valid || empty($value)) {
        return $valid;
      }
      $posts_ids = $value;
      if (!is_array($posts_ids)) {
        $posts_ids = array($posts_ids);
      }
      $messages = array();
      foreach ($posts_ids as $post_id) {
        $remote_value = get_field($field['name'], $post_id);
        if (empty($remote_value)) {
          continue;
        }
        if (!is_array($remote_value)) {
          $remote_value = array($remote_value);
        }
        $max_posts = 0;
        $remote_field_object = get_field_object($field['name'], $post_id);
        if ($remote_field_object['type'] == 'post_object') {
          if (!$remote_field_object['multiple']) {
            $max_posts = 1;
          }
        } elseif ($remote_field_object['type'] == 'relationship') {
          if ($remote_field_object['max']) {
            $max_posts = $remote_field_object['max'];
          }
        }
        if ($max_posts > 0 && count($remote_value) == $max_posts && !in_array($post->ID, $remote_value)) {
          $remote_post = get_post($post_id);
          $messages[] = $remote_post->post_title.' cannot be selected';
        }
      } // end foreach
      if (!empty($messages)) {
        $valid = implode('<br />', $messages);
      }
      return $valid;
    } // end function
    

    There is also no mechanism in ACF to disable (“gray out”) a value in a select2 field so that it is not selectable. The only thing that could possibly be done here is to use an acf/fields/relationship/query or acf/fields/post_object/query filter to filter out posts that cannot be selected by adding a “post__not_in ” argument. Similar but more complicated than the above filter. However, such a filter would likely be detrimental to performance because you’d need to look at the value of every possible post that could be selected to determine if selection would mean the other post would have too many. In all likely hood this would time out the AJAX request and just break the field.

    • This reply was modified 4 years, 4 months ago by John Huebner.
    Plugin Author John Huebner

    (@hube2)

    When you say that you are using quick edit, is this only to change a post from draft to publish or are you somehow editing the relationship field in quick edit.

    If you are just publishing the post, I tested this and it works as expected.

    If you are trying to edit the relationship field in quick edit somehow, this plugin does not have the ability to update the relationship on the other end unless whatever you’re using calls the acf function update_field(), to update the relationship value. This plugin depends on the acf/update_value hook being triggered.

    Thread Starter John Huebner

    (@hube2)

    Plugin Author John Huebner

    (@hube2)

    also, what code are you using to display these relationships on the front end?

    If the correct posts appear in the relationshipd fields in the admins of all posts then this is all that this plugin does.

    There shouldn’t be any reason except for those I’ve noted that it should not work.

    There is another condition that could cause this.

    If you have both sites of the relationship open in the admin and you attempt to updated them both then they will be updated with the current values in the fields. If Post A is saved with a relationship to post B then you much reload post B in the admin to see that relationship. Updating without doing this will cause the relatiohsip to post A to be removed.

    Plugin Author John Huebner

    (@hube2)

    Do the fields on both post type have identical field names?

    Plugin Author John Huebner

    (@hube2)

    Are you using a relationship fields or post object fields?

    If it’s a relationship field what is there a max number of posts set for it?

    If it’s a post object field is “Select Multiple Values” set to “Yes”

    This plugin will only create relationships up to the maximum allowed by the field’s settings.

    Thread Starter John Huebner

    (@hube2)

    That corrected the issue for me.

    Thread Starter John Huebner

    (@hube2)

    Just did a test on another site that is not multisite. Everything is working fine. Must be something in the difference between how permissions are checked on multisite and the fact that only super admin can install plugins. The exact issue still eludes me. Something that is not set up to deal with multisite in the dependency installer.

    Thread Starter John Huebner

    (@hube2)

    Really confusing since I can’t find any reference to either of these constants in this plugin.

    Plugin Author John Huebner

    (@hube2)

    There isn’t a way to remove them.

    Honestly, you should not use this plugin, it does not work in all cases. Most people need options like this rarely and only for a couple of fields. It is better to do this yourself using an acf/prepeare_field filter for only the fields you want to restrict or to put the fields into their own field group and use location rules to limit who can edit the fields.

    Plugin Author John Huebner

    (@hube2)

    This plugin will not cause errors when deactivated.

    Plugin Author John Huebner

    (@hube2)

    I’m not sure what you are asking, but I am guessing.

    This plugin cannot be used retroactively and it does not have the ability to update bidirectional relationship fields that already have values.

    To get the fields to update you will have to manually update the posts on one side of each relationship.

    Plugin Author John Huebner

    (@hube2)

    This is correct and I do not know if what you want to do is possible. You might be able to use an acf/prepare_field filter to alter the label of the field if you can detect a difference in the post.

    This plugin has a very simple use case. For your case I would likely use to fields and custom code the bidirectionality

    Plugin Author John Huebner

    (@hube2)

    A single field on one post type is automatically bidirectional when this plugin is active because the field exists for all posts on the post type.

Viewing 15 replies - 61 through 75 (of 564 total)