1

Is there a way to change filter labels for custom post type? For example, change Drafts (2) to Disabled (2) without localization plugins like Loco Translate?

enter image description here

I've tried apply_filters( "views_{$this->screen->id}", $views ); filter, but array already contains links with html. Regex doesn't looks "the right way".

Array
(
    [all] => <a href="edit.php?post_type=sha-wlc" class="current" aria-current="page">All <span class="count">(13)</span></a>
    [publish] => <a href="edit.php?post_status=publish&#038;post_type=sha-wlc">Published <span class="count">(11)</span></a>
    [draft] => <a href="edit.php?post_status=draft&#038;post_type=sha-wlc">Drafts <span class="count">(2)</span></a>
    [trash] => <a href="edit.php?post_status=trash&#038;post_type=sha-wlc">Trash <span class="count">(1)</span></a>
)

1 Answer 1

1

Here's an untested way to override it, based on my older answer:

add_action( 'init', function() {   
    $vars = get_object_vars( 
        get_post_status_object( 'draft' ) 
    );
    $vars['label_count'] = _n_noop(
        'Disabled <span class="count">(%s)</span>',
        'Disabled <span class="count">(%s)</span>',
        'wpse-domain'
    );
    register_post_status( 'draft', $vars );
}, 1 );

We use the priority 1, since the default draft status is registered at priority 0. You might look into the $vars['label'] as well.

4
  • Thanks! Great solution. I didn't noticed from core register_post_status function, that status labels with the same status id merged. May 9 at 14:56
  • Glad to hear it helped
    – birgire
    May 9 at 21:35
  • seems like I rejoiced early. Using existing status in register_post_status affecting all records, so for default posts this also change labels May 10 at 16:58
  • Ok. thx for updates, Yes the status api is not finished aka core.trac.wordpress.org/ticket/12706. Maybe preg_replace or similar, on your filter can help in the meanwhile.
    – birgire
    May 10 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.