0

I try to translate post types names (Post, Page and Attachment).

I have the following code:

function create_skip_post_types_box () {
        $post_types = get_post_types(array('public'=>true), 'names' );
        $opt = $this->_get_option();
        $skip_types = is_array(@$opt['skip_post_types']) ? @$opt['skip_post_types'] : array();

        foreach ($post_types as $tid=>$type) {
            $checked = in_array($type, $skip_types) ? 'checked="checked"' : '';
            echo
                "<input type='hidden' name='wdpv[skip_post_types][{$type}]' value='0' />" . // Override for checkbox
                "<input {$checked} type='checkbox' name='wdpv[skip_post_types][{$type}]' id='skip_post_types-{$tid}' value='{$type}' /> " .
                "<label for='skip_post_types-{$tid}'>" . ucfirst($type) . "</label>" .
            "<br />";
        }
    }

I tried to use ucfirst(__($type,'textdomain')) but it didn't work.

I know that for user roles we can use translate_user_role function, but what about post types?

Thank you!

1
  • It is not clear what exactly are you trying to. Do you mind adding to your code the translation calls as you think they should be? Aug 16 '14 at 17:10
1

Use get_post_types( ['public' => TRUE ], 'objects' );. This will return the already translated post type labels and other information.

Example for tests:

add_action( 'wp_footer', function() {
    $post_types = get_post_types(
        [ 'public' => TRUE, '_builtin' => TRUE ],
        'objects' // complete information, not just the name
    );

    foreach ( $post_types as $slug => $arguments )
        print "$slug: {$arguments->labels->singular_name}<br>";

    print '<pre>' . print_r( $post_types, 1 ) . '</pre>';
});
0

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.