Title: _nx
Published: April 25, 2014
Last modified: August 20, 2026

---

# _nx( string $single, string $plural, int $number, string $context, string $domain = 'default' ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#wp--skip-link--target)

Translates and retrieves the singular or plural form based on the supplied number,
with gettext context.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#description)󠁿

This is a hybrid of [_n()](https://developer.wordpress.org/reference/functions/_n/)
and [_x()](https://developer.wordpress.org/reference/functions/_x/) . It supports
context and plurals.

Used when you want to use the appropriate form of a string with context based on
whether a number is singular or plural.

Example of a generic phrase which is disambiguated via the context parameter:

    ```php
    printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
    printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );
    ```

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#parameters)󠁿

 `$single`stringrequired

The text to be used if the number is singular.

`$plural`stringrequired

The text to be used if the number is plural.

`$number`intrequired

The number to compare against to use either the singular or plural form.

`$context`stringrequired

Context information for the translators.

`$domain`stringoptional

Text domain. Unique identifier for retrieving translated strings.
 Default `'default'`.

Default:`'default'`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#return)󠁿

 string The translated singular or plural form.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#source)󠁿

    ```php
    function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
    	$translations = get_translations_for_domain( $domain );
    	$translation  = $translations->translate_plural( $single, $plural, $number, $context );

    	/**
    	 * Filters the singular or plural form of a string with gettext context.
    	 *
    	 * @since 2.8.0
    	 *
    	 * @param string $translation Translated text.
    	 * @param string $single      The text to be used if the number is singular.
    	 * @param string $plural      The text to be used if the number is plural.
    	 * @param int    $number      The number to compare against to use either the singular or plural form.
    	 * @param string $context     Context information for the translators.
    	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
    	 */
    	$translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );

    	/**
    	 * Filters the singular or plural form of a string with gettext context for a domain.
    	 *
    	 * The dynamic portion of the hook name, `$domain`, refers to the text domain.
    	 *
    	 * @since 5.5.0
    	 *
    	 * @param string $translation Translated text.
    	 * @param string $single      The text to be used if the number is singular.
    	 * @param string $plural      The text to be used if the number is plural.
    	 * @param int    $number      The number to compare against to use either the singular or plural form.
    	 * @param string $context     Context information for the translators.
    	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
    	 */
    	$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );

    	return $translation;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/l10n.php#L542)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/l10n.php#L542-L577)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#hooks)󠁿

 [apply_filters( ‘ngettext_with_context’, string $translation, string $single, string $plural, int $number, string $context, string $domain )](https://developer.wordpress.org/reference/hooks/ngettext_with_context/)

Filters the singular or plural form of a string with gettext context.

 [apply_filters( “ngettext_with_context_{$domain}”, string $translation, string $single, string $plural, int $number, string $context, string $domain )](https://developer.wordpress.org/reference/hooks/ngettext_with_context_domain/)

Filters the singular or plural form of a string with gettext context for a domain.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#related)󠁿

| Uses | Description | 
| [get_translations_for_domain()](https://developer.wordpress.org/reference/functions/get_translations_for_domain/)`wp-includes/l10n.php` |

Returns the Translations instance for a text domain.

  | 
| [Translations::translate_plural()](https://developer.wordpress.org/reference/classes/translations/translate_plural/)`wp-includes/pomo/translations.php` |

Translates a plural string.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#)

| Used by | Description | 
| [WP_Privacy_Requests_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_privacy_requests_table/get_views/)`wp-admin/includes/class-wp-privacy-requests-table.php` |

Gets an associative array ( id => link ) with the list of views available on this table.

  | 
| [WP_MS_Users_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_ms_users_list_table/get_views/)`wp-admin/includes/class-wp-ms-users-list-table.php` |  | 
| [WP_Plugins_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_plugins_list_table/get_views/)`wp-admin/includes/class-wp-plugins-list-table.php` |

Gets an associative array of status filter links for the views area.

  | 
| [WP_MS_Themes_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_ms_themes_list_table/get_views/)`wp-admin/includes/class-wp-ms-themes-list-table.php` |

Gets the list of views (statuses) for the list table.

  | 
| [install_plugin_information()](https://developer.wordpress.org/reference/functions/install_plugin_information/)`wp-admin/includes/plugin-install.php` |

Displays plugin information in dialog box form.

  | 
| [WP_Plugin_Install_List_Table::display_rows()](https://developer.wordpress.org/reference/classes/wp_plugin_install_list_table/display_rows/)`wp-admin/includes/class-wp-plugin-install-list-table.php` |

Generates the list table rows.

  | 
| [WP_Users_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_users_list_table/get_views/)`wp-admin/includes/class-wp-users-list-table.php` |

Returns an associative array listing all the views that can be used with this table.

  | 
| [WP_Posts_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/get_views/)`wp-admin/includes/class-wp-posts-list-table.php` |  | 
| [translate_nooped_plural()](https://developer.wordpress.org/reference/functions/translate_nooped_plural/)`wp-includes/l10n.php` |

Translates and returns the singular or plural form of a string that’s been registered with [_n_noop()](https://developer.wordpress.org/reference/functions/_n_noop/) or [_nx_noop()](https://developer.wordpress.org/reference/functions/_nx_noop/) .

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_nx/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced `ngettext_with_context-{$domain}` filter. | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_nx%2F)
before being able to contribute a note or feedback.