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

Show posts of category in a page

The way i’d do it: First – create a page in the wp admin. Then create a file like mypage.php. Save it in your theme and a the top of it, add this to tell wordpress that this is a custom page template: <?php /* Template Name: Custompage */ get_header(); ?> Note: it’ll also already … Read more