• Resolved xavierbiron

    (@xavierbiron)


    Hello,

    I want to not copy an ACF field during the duplication. My ACF field is field_5784087756dbe. I’ve tried to add it in the “do not copy these fields” in the settings page, but it still being copied.
    I’ve tried with this code in functions.php :

    /** 
     * Filters out custom fields from being duplicated in addition to the defaults.
     *
     * @param array $meta_excludelist The default exclusion list, based on the “Do not copy these fields” setting, plus some other field names.
     *
     * @return array The custom fields to exclude.
     */
    function my_custom_fields_filter( $meta_excludelist ) {
        // Merges the defaults array with our own array of custom fields.
        return array_merge( $meta_excludelist, [ 'field_5784087756dbe' ] );
    }
    
    add_filter( 'duplicate_post_excludelist_filter', 'my_custom_fields_filter' );

    Same result. And this filter seems to not even being fired. Can you help me ?
    Thank you very much.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Enrico Battocchi

    (@lopo)

    Hi @xavierbiron,
    the filter hook is currently called duplicate_post_blacklist_filter. We are aware there is a different name in the Yoast documentation and we are working on this inconsistency.
    Can you try by using the name above?

    Also, are you sure that’s the correct name for the custom field? From what I know about ACF, usually the strings field_123456789are used internally as keys to manage the type and settings for that field, but in the wp_postmeta table the value is stored using the “field name” you input while creating the field in ACF… which is usually the uncapitalised and sanitised label for the field.

    Let me know if this helps and again apologies for the inconsistency in the documentation!

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @xavierbiron,
    the new version 3.2.5 which has just been released deprecates duplicate_post_blacklist_filter in favor of duplicate_post_excludelist_filter.
    This should fix your issue, provided that you use the actual custom fields names instead of ACF keys…

    Let me know!

    Thread Starter xavierbiron

    (@xavierbiron)

    Hello,

    Sorry for the delay. I have the 3.2.5 version, and still have the issue.
    Here is my code

    function my_custom_fields_filter( $meta_excludelist ) {
        return array_merge( $meta_excludelist, [ 'field_5fc914ebe8a22' ] );
    }
    
    add_filter( 'duplicate_post_excludelist_filter', 'my_custom_fields_filter' );

    I confirm that field_5fc914ebe8a22 is the good ACF key for the field I want to exclude.

    Thanks for the support

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @xavierbiron,
    you should use the field name instead of the key: that is the name that is stored in the meta_key column of the wp_postmeta table, and usually is a “sanitized” version of the field’s label.

    Let us know if this helps!

    Thread Starter xavierbiron

    (@xavierbiron)

    Thanks a lot Enrico, it worked with the name of the field instead of the key.
    SOLVED

    Plugin Author Enrico Battocchi

    (@lopo)

    Hi @xavierbiron,
    glad to hear that! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Do not copy ACF field’ is closed to new replies.