Category nicename inside loop in wordpress

You can use get_the_category inside the loop to get the category/ies a post is assigned to. To get a list of available member variables available, see get_categories. I would suggest to target the first category only, which will also be the parent category if the post is assigned to only one parent and some of … Read more

ID of last created category

There’s no 100% reliable way of doing this, as no date or timestamp is attached to the category in the database table. Any solution you find would be a partial solution that will never work 100% The closest available would be these answers: https://stackoverflow.com/questions/2770600/mysql-select-the-last-inserted-row-easiest-way By assuming the category with the highest term ID was the … Read more

Show all sub categories?

To exclude parent categories from your term list, you can just pass over them after you have retrieved your term list with get_terms Example: <?php $args = array( ‘orderby’ => ‘name’, ); $terms = get_terms( ‘mytaxname’, $args ); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ foreach ( $terms as $term ) { … Read more

Add posts of a certain category to a page

Create a page template and use wp_query to target the category you want to display $args = array(‘category_name’ => ‘your category name’,); WP_Query will help you with all sorts of options for what posts are returned and get displayed by your loop. Here is an example of a page template, (this is based on the … Read more

Cannot filter categories by parent category

To get direct descendants (i.e. children only) of the category, you need to make use of the parent parameter in get_categories() The reason why you might not see your other category is that it does not have any posts assigned to it. To display empty categories, you need to set the hide_empty parameter to 0 … Read more