Tag Info

Hot answers tagged


the id of the categories is autoincrement so you can sort by id to find the last one : $args = array( "type" => "post", "orderby" => "id", "order" => "DESC", "number" => "5", "taxonomy" => "category", "hide_empty" => FALSE, // TRUE or FALSE depending what you want ); $categories = get_categories($args);


As of PHP 5.4, you can directly dereference an array, so to get the first term, you can simply do. $first_term = get_the_terms( $post->ID, 'TAXONOMY_NAME' )[0]; var_dump( $first_term ); If you need a specific property (say the term name) of the first term, you can do the following $first_term_name = get_the_terms( $post->ID, 'TAXONOMY_NAME' ...


use this code for access categories $args = new WP_Query( array( 'type' = 'post', 'taxonomy' = 'taxonomy_name', 'order' = 'ASC', 'orderby' = 'id' )); //this function are used for access all categories $query = get_categories($args);

Only top voted, non community-wiki answers of a minimum length are eligible