Hot answers tagged

3

To delete a category from WP , first you need to open the category listing. It will come when you will mouse over the Posts. Once you click on Categories, it will display all the categories. Then mouse over to the category which you want to delete and it will show you an Delete link. You just need to click on Delete and choose "OK" from the Alert box....


2

For getting the posts related to each category you need to use get_posts( $args ) function and in $args you can add your category_id $args = array ( 'post_type' => 'post', 'category' => $cat_ID, 'post_status' => 'publish', ); $my_posts = get_posts( $args ); // return array of posts // storing all post ID in an array foreach( ...


2

This would be quite challenging to implement. Posts can be trashed because: They have a concept of status and corresponding field in database table WordPress code "knows" to only deal with posts of appropriate status for most purposes This solves issues of visibility (posts won't appear on front end) and interaction (trashed posts won't show up as ...


1

You can just run through the loop and set a flag: if ( $query->have_posts() ) : $any_in_cat = false; while ( $query->have_posts() ) : $query->the_post(); if ( in_category( 'first-major' ) ) : $any_in_cat = true; endif; endwhile; $query->rewind_posts(); /* if $any_in_cat == true at this point then ...


1

You can create a separate function to check your array of posts contains a post with that category. It will basically do what you are now but it will allow you to call the function once instead of each time through the loop. You would put this code in your functions.php file: function does_array_contain_category( $categories, $posts ){ foreach( $posts ...


1

It will take a bit of programming on your side but you can use the delete_term_taxonomy hook to create a trash for the categories. It is run just before the category is deleted.


1

I needed some modifications(original see Pieters answer) to get it to work just on category pages. This solution will display all sticky posts of the current category (and child categories), but not on search, tag and single pages: add_action( 'pre_get_posts', function ( $q ) { if ( !is_admin() && $q->is_main_query() &&...



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