Send an email when custom post type category is changed

Use the hooks added_term_relationship and deleted_term_relationships. These only fire when the relationship changes, as opposed to set_object_terms which always fires: function wpse_181090_object_terms_updated( $object_id ) { static $did = array(); // This function might fire multiple times for the same object, ensure it only runs once if ( ! isset( $did[ $object_id ] ) ) { … Read more

Trash bin for categories

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 … Read more

List categories for author: list_categories function inside list_authors function

Seemed interesting, so here is my version. Not sure about get_user_by(), should be more robust way to get objects for authors. function my_list_authors() { $authors = wp_list_authors( array( ‘exclude_admin’ => false, ‘html’ => false, ‘echo’ => false ) ); $authors = explode( ‘,’, $authors ); echo ‘<ul>’; foreach ( $authors as $author ) { $author … Read more

How to create a widgetized sidebar for every category dynamically?

Not a good thing if you have a lot of categories, so be careful! First, add the following function in functions.php: add_action( ‘widgets_init’, ‘generate_widget_areas’ ); function generate_widget_areas() { //Do not create for uncategorized category $terms = get_categories(‘exclude=1&hide_empty=0’); foreach ($terms as $term) { register_sidebar( array( ‘name’ => ‘Category ‘.$term->name, ‘id’ => $term->slug.’-widget-area’, ‘description’ => ‘Widget area … Read more

Rewrite category wordpress

You can do this with a rewrite rule from within WordPress. Take a look at the documentation for add_rewrite_rule. Something like this: <?php add_action(‘init’, ‘wpse65855_rewrite’); function wpse65855_rewrite() { add_rewrite_rule( ‘^photos/?$’, // the rule regex ‘index.php?taxonomy=category&term=photos’, // where you want the rule to go ‘top’ // the priority. Make this one go first ); } You … Read more

Create product category and keyword search form in woocommerce? [closed]

I just made it for a client, you’ll have to do it on the pre_get_posts action. That means you will add parameters to the WordPress query before it returns the posts. Add this to functions.php: // advanced search functionality function advanced_search_query($query) { if($query->is_search()) { // category terms search. if (isset($_GET[‘category’]) && !empty($_GET[‘category’])) { $query->set(‘tax_query’, array(array( … Read more

404 error on subcategory pages

The cause of this issue for future reference was the ‘.’ in the category base, which was added to resolve a previous issue. Removing this and using /category/postname (per question) works, so will look for an alternative resolution to the category base issue.