• bhkh

    (@bhkh)


    (I posted this in a previous thread, but it was already marked as resolved)

    Hello!

    I am trying to follow your instructions from this previous thread,. To my custom plugin I have added the following

    /**  * 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, [ 'ig_es_is_post_notified', 'bluesky_shared' ] );}add_filter( 'duplicate_post_excludelist_filter', 'my_custom_fields_filter' );

    However when I click “Rewrite & Republish” and the post opens for republishing in the custom fields section I still see this:

    My understanding of your instructions was that these fields should not be duplicated because of the function you recommended.

    I am confident that my custom plugin is active.

    Can you tell me what I am doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Mushrit Shabnam

    (@611shabnam)

    Hi @bhkh

    The filter duplicate_post_excludelist_filter works when you use the clone or new draft option. So you need to modify the code to make the filter available for Rewrite and Republish feature.

    We recommend creating regular backups of your site and database for your site’s health and safety. A backup is crucial before making important changes on your website and provides you with a safety net if something were to go wrong. Learn more about the benefits of regular backups.

    Thread Starter bhkh

    (@bhkh)

    Thanks!

    Are you able to help me out with that? It’s not clear to me from that page how I would do that.

    Thread Starter bhkh

    (@bhkh)

    I can see that in src\post-duplicator.php there is create_duplicate_for_rewrite_and_republish

    public function create_duplicate_for_rewrite_and_republish( WP_Post $post ) {
    $options = [
    'copy_title' => true,
    'copy_date' => true,
    'copy_name' => false,
    'copy_content' => true,
    'copy_excerpt' => true,
    'copy_author' => true,
    'copy_menu_order' => true,
    'use_filters' => false,
    ];
    $defaults = $this->get_default_options();
    $options = \wp_parse_args( $options, $defaults );

    $new_post_id = $this->create_duplicate( $post, $options );

    if ( ! \is_wp_error( $new_post_id ) ) {
    $this->copy_post_taxonomies( $new_post_id, $post, $options );
    $this->copy_post_meta_info( $new_post_id, $post, $options );

    etc.

    The copy_post_meta_info seems to be called. And that is where duplicate_post_excludelist_filter is used.

    So I don’t see why it’s not working.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘`duplicate_post_excludelist_filter` not working as expected’ is closed to new replies.