ACF Post-2-Post

Descripción

Este plugin es una extensión para Advanced Custom Fields (ACF) versión 5.

Este plugin no funcionará con la versión 4 de ACF.

Este plugin no proporcionará ninguna funcionalidad si ACF5 no está instalado.***

Este plugin no crea un nuevo tipo de campo ni ninguna interfaz de administración. Este plugin, cuando se usa
como se explica a continuación, hace que los campos de relación y objeto de ACF existentes funcionen de forma bidireccional,
actualizando automáticamente el campo de relación en el otro extremo de la relación.

Para más información, véase Otras notas

Github Repository

This plugin is also on GitHub
https://github.com/Hube2/acf-post2post

How To Use

  • Create a relationship or post object field.
  • The field must be at the top level. It cannot be a subfield of a repeater or a flexible content field.
  • The field name must be the same on all posts. In other words if you want to have different post types be related then you must add a field with the same field name on both post types.

When you add a post to a relationship or post object field and the same field name appears on the post added to the relationship then the relationship field on the related post will be updated to include a relationship to the post being edited.

If a post is removed from a relationship then the post being removed will also be updated to remove the relationship to the post being edited.

Post Object Fields

If a post object field is being used

  • If it allows multiple values then it will work the same way that relationship fields work.
  • If it does not allow multiple values and the related post already contains a value see Overwrite Settings

Overwrite Settings

If the field in a related post, whether it is a post object field that only allows 1 value or a relationship field that has a maximum number of related posts, if the field in the related post already has the maximum number of values allowed, by default, a new value will not be added. You can override this default by specifying overwrite settings.

How to add overwrite settings

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

Each element of the $settings array is an array. The index of the array is the field that you want to specify settings for. Each field can have 2 arguments.

  • overwrite: true/false or 1/0. If set to true or 1 then new values will overwrite older values. The default value of this setting is false.
  • type: ‘first’ or ‘last’. Which of the existing values should be removed, the first one added or the last. The default value is ‘first’.

after a value is removed from the existing list the new value is added to the end of the list.

Excepciones de campo

Puedes desactivar las relaciones bidireccionales automáticas para claves de campo específicas utilizando el filtro

// field_XXXXXXXX = the field key of the field
// you want to disable bidirectional relationships for
add_filter('acf/post2post/update_relationships/key=field_XXXXXXXX', '__return_false');

Ganchos tras actualizar

Hay dos acciones que se pueden utilizar después de que una entrada se actualiza y pasa un único ID de mensaje. Por favor, asegúrate de ver la sutil diferencia entre estos dos ganchos.

La primera se ejecuta después de actualizar cada entrada relacionada.

add_action('acf/post2post/relationship_updated', 'my_post_updated_action');
function my_post_updated_action($post_id) {
  // $post_id == the post ID that was updated
  // do something after the related post is updated
}

La segunda se ejecuta después de actualizar todas las entradas y pasa un array de IDs de entradas.

add_action('acf/post2post/relationships_updated', 'my_post_updated_action');
function my_post_updated_action($posts) {
  // $posts == and array of post IDs that were updated
    // do something to all posts after update
    foreach ($posts as $post_id) {
      // do something to post
    }
}

Instalación

Instalar como cualquier otro plugin

FAQ

Nada aún

Reseñas

18 de agosto de 2020
We had ~10 different post types and fields all over the place. Just make sure the custom field names are the same across post types and it works flawlessly! Thanks a heap!
7 de mayo de 2020
Works perfectly with ACF Pro Version 5.8.8 - can't understand why isn't it included in ACF core. Epic!
24 de enero de 2020
Incredibly useful if you need to create relationships between objects of different post types.
1 de noviembre de 2019
If you're dealing with large data sets, this plugin can save massive amounts of query time and speed up your site. Like everyone else said, it's a "must have"!
14 de octubre de 2019
Hi John, thanks alot for this extension - which covers a very important area, when dealing with theme development.
Leer todas las 29 reseñas

Colaboradores y desarrolladores

«ACF Post-2-Post» es un software de código abierto. Las siguientes personas han colaborado con este plugin.

Colaboradores

Traduce «ACF Post-2-Post» a tu idioma.

¿Interesado en el desarrollo?

Revisa el código , echa un vistazo al repositorio SVN o suscríbete al registro de desarrollo por RSS.

Registro de cambios

1.5.0

  • Added filter to allow specifying to append or prepend new relationship (can supercede overwrite setting)

1.4.1

  • Corrected logic error in overwrite
  • add context to action hooks

1.4.0

  • added actions after updates to related posts to allow 3rd party integrations

1.3.2

  • removed donation nag

1.3.1

  • Corrected bug in 1.3.0 that prevented all fields from updating correctly

1.3.0

  • added filter to allow disabling bidirectional relationships on fields by field key

1.2.8

  • changed from plugins_loaded to after_setup_theme for checking if ACF >= 5 is installed to allow for ACF being installed in themes

1.2.7

  • replace php array_walk() w/array_map() to correct issue with str/int conversion of IDs

1.2.6

  • corrected serialization of post IDs as strings instead of integers to allow correct ACF meta_key value searching of serialized ID values useing LIKE "{ID}"

1.2.5

  • plugin disabled if ACF5 not installed
  • plugin deactivated if ACF5 not installed

1.2.4

  • removed github updater support

1.2.3

  • initial release to WordPress.org