How to stop wordpress from showing the selected category on top of others in the category selection?

If I got this right, you need this plugin: Category Checklist Tree. On the post editing screen, after saving a post, you will notice that the checked categories are displayed on top, breaking the category hierarchy. This plugin removes that “feature”. Additionally, it automatically scrolls to the first checked category. Works with custom taxonomies too.

Return category slug / title from category ID

get_category will return all the information you need for both cases. $catinfo = get_category(get_field(‘category_test’)); From the Codex, that will give you (sample data obviously): stdClass Object ( [term_id] => 85 [name] => Category Name [slug] => category-name [term_group] => 0 [term_taxonomy_id] => 85 [taxonomy] => category Return category slug / title from category ID => … Read more

Getting category before saving post

Yes, and you’re quite close to it. Just use the $postarr parameter of this filter: add_filter( ‘wp_insert_post_data’ , ‘wpse128138_wp_insert_post_data’, 99, 2 ); function wpse128138_wp_insert_post_data( $data, $postarr ) { // run this only for posts if ( ‘post’ != $postarr[‘post_type’] ) return $data; foreach( $postarr[‘post_category’] as $category_id ) { if ( is_wp_error( $category = get_category( $category_id … Read more

Get a variable from object in array [closed]

Probably your hosting server has a different and older version of php so this syntax is not supported. The above syntax is implemented in PHP 5.4. You have to do it like this: $category = get_the_category($id); echo $category[0]->slug; Source: https://bugs.php.net/bug.php?id=45906

I want exclude the particular category in sidebar

Notice that you don’t need echo to display the result, since echo=1 is the default settings of wp_get_archives(). As @PieterGoosen explained, the wp_get_archives() function doesn’t support the exclude parameter. But we can use _exclude_terms, the custom parameter of the wp_get_archives() function, to exclude posts with some given terms. Here’s an example: /** * Exclude terms … Read more

Get a list of Terms for a specific category

The following code will do it. Please change the ‘filter’ text in the below code to whatever filters taxonomy name you have set. if(is_category() ){ $thiscat = get_queried_object_id(); $filter_tax = array(); $args = array( ‘category’ => $thiscat ); $lastposts = get_posts( $args ); foreach ( $lastposts as $post ){ setup_postdata( $post ); $terms = get_the_terms( … Read more

Check is category parent or not from its ID

You can do something like this: function category_has_parent($catid){ $category = get_category($catid); if ($category->category_parent > 0){ return true; } return false; } and use it like this: if (category_has_parent(’22’)){ //true there is a parent category }else{ //false this category has no parent } Update: to check the other way around (if a category has children) you … Read more