wp_popular_terms_checklist

The timeline below displays how wordpress function wp_popular_terms_checklist has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves a list of the most popular terms from the specified taxonomy.
 *
 * If the `$display` argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the `$post_ID` global is not empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy     Taxonomy to retrieve terms from.
 * @param int    $default_term Optional. Not used.
 * @param int    $number       Optional. Number of terms to retrieve. Default 10.
 * @param bool   $display      Optional. Whether to display the list as well. Default true.
 * @return int[] Array of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default_term = 0, $number = 10, $display = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms(array('taxonomy' => $taxonomy, 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$display) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms, true) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name, '', ''));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 5.5

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int    $default  Not used.
 * @param int    $number   Number of terms to retrieve. Defaults to 10.
 * @param bool   $echo     Optionally output the list as well. Defaults to true.
 * @return int[] Array of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms(array('taxonomy' => $taxonomy, 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms, true) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name, '', ''));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 5.4

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int    $default  Not used.
 * @param int    $number   Number of terms to retrieve. Defaults to 10.
 * @param bool   $echo     Optionally output the list as well. Defaults to true.
 * @return int[] Array of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms(array('taxonomy' => $taxonomy, 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name, '', ''));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 5.3

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Not used.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms(array('taxonomy' => $taxonomy, 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name, '', ''));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 4.9

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Not used.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name, '', ''));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 4.6

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Not used.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // Hack for Ajax use.
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 4.2

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Not used.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // hack for AJAX use
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 4.1

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * `<input>` elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Unused.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // hack for AJAX use
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 3.9

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * <input> elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Unused.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // hack for AJAX use
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        /** This filter is documented in wp-includes/category-template.php */
        echo esc_html(apply_filters('the_category', $term->name));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}

WordPress Version: 3.7

/**
 * Retrieve a list of the most popular terms from the specified taxonomy.
 *
 * If the $echo argument is true then the elements for a list of checkbox
 * <input> elements labelled with the names of the selected terms is output.
 * If the $post_ID global isn't empty then the terms associated with that
 * post will be marked as checked.
 *
 * @since 2.5.0
 *
 * @param string $taxonomy Taxonomy to retrieve terms from.
 * @param int $default Unused.
 * @param int $number Number of terms to retrieve. Defaults to 10.
 * @param bool $echo Optionally output the list as well. Defaults to true.
 * @return array List of popular term IDs.
 */
function wp_popular_terms_checklist($taxonomy, $default = 0, $number = 10, $echo = true)
{
    $post = get_post();
    if ($post && $post->ID) {
        $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
    } else {
        $checked_terms = array();
    }
    $terms = get_terms($taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false));
    $tax = get_taxonomy($taxonomy);
    $popular_ids = array();
    foreach ((array) $terms as $term) {
        $popular_ids[] = $term->term_id;
        if (!$echo) {
            // hack for AJAX use
            continue;
        }
        $id = "popular-{$taxonomy}-{$term->term_id}";
        $checked = in_array($term->term_id, $checked_terms) ? 'checked="checked"' : '';
        ?>

		<li id="<?php 
        echo $id;
        ?>" class="popular-category">
			<label class="selectit">
			<input id="in-<?php 
        echo $id;
        ?>" type="checkbox" <?php 
        echo $checked;
        ?> value="<?php 
        echo (int) $term->term_id;
        ?>" <?php 
        disabled(!current_user_can($tax->cap->assign_terms));
        ?> />
				<?php 
        echo esc_html(apply_filters('the_category', $term->name));
        ?>
			</label>
		</li>

		<?php 
    }
    return $popular_ids;
}