Цей плагін не перевірявся з останніми 3-ма основними випусками WordPress. Можливо, він більше не може розроблятися або підтримуватися, і він може мати проблеми сумісності при використанні з більш новими версіями WordPress.

Limit taxonomy term count

Опис

By default WordPress does not allow you to limit how many taxonomy terms can be attached to a post.
Enabling this plugin allows the use of the “limit” attribute when initially calling register_taxonomy().
If the limit is set to 1 then only one term can be added to the post. If the limit is greater than one then that many
terms may be added to the post. If the limit is attribute is not set, or it’s set to -1 this plugin has no effect.

Example code showing the use of the limit attribute:

register_taxonomy('artists', 'art_work', [
    'label'             => 'Artists',
    'show_ui'           => true,
    'limit'             => 1,
]);

This example shows the use of a custom taxonomy called “artists” and the post type is “art_work”.

Here is another example but this time it’s editing the previously registered taxonomy “post_tag”:

// First load the taxonomy
$taxonomy = get_taxonomy('post_tag');

// Edit it to only allow 2 tags to be added per post
$taxonomy->limit = 2;

// Re-save it with our updated settings (note casting the object to an array before saving)
register_taxonomy('post_tag', 'post', (array)$taxonomy);

Встановлення

The easiest way to install this plugin is to go to Add New in the Plugins section of your blog admin and search for
“Limit taxonomy term count.” On the far right side of the search results, click “Install.”

If the automatic process above fails, follow these simple steps to do a manual install:

  1. Extract the contents of the zip file into your /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress

Часті питання

Can I edit settings passed to select2?

Yes, you can use the filter limit_taxonomy_term_count_js_data to make any changes to settings.

E.g.

add_filter('limit_taxonomy_term_count_js_data', 'my_plugin_limit_taxonomy_term_count_js_data');
function my_plugin_limit_taxonomy_term_count_js_data($data) {
    foreach($data as $taxonomy_name => &$settings) {
        if($taxonomy_name == 'this_is_the_taxonomy_your_looking_for') {
            // This is the array of settings passed to select2:
            print_r($settings['select2_options']);
        }
    }
    return $data;
}

Відгуки

Прочитати всі 1 відгук

Учасники та розробники

“Limit taxonomy term count” — проект з відкритим вихідним кодом. В розвиток плагіну внесли свій вклад наступні учасники:

Учасники

Перекладіть “Limit taxonomy term count” на вашу мову.

Цікавитесь розробкою?

Перегляньте код, перегляньте сховище SVN або підпишіться на журнал розробки за допомогою RSS.

Журнал змін

1.0

  • First version released.