How to change the category in URL for posts in multiple categories?

Similar plugin but compatible to latest wp version 3.5.2 http://wordpress.org/plugins/wp-category-permalink/ This plugin allows you to select a ‘main’ category for your posts, for better permalinks and SEO. It uses the same meta data as the “Hikari Category Permalink” and the “sCategory Permalink”, but it has been rewritten using better and cleaner code. Requires: WP 3.5 … Read more

wp_update_nav_menu_item() to insert categories

After using the Chrome inspector on the “Appearance > Menus” categories panel I was able to sniff out the hidden form values that are passed when one manually adds a category to a custom menu via the wizard: <li> <label class=”menu-item-title”> <input type=”checkbox” class=”menu-item-checkbox” name=”menu-item[-11][menu-item-object-id]” value=”181″> Category One</label> <input type=”hidden” class=”menu-item-db-id” name=”menu-item[-11][menu-item-db-id]” value=”0″> <input type=”hidden” … Read more

how to use a different domain/subdomain for authors/catagories on single site?

wp-config.php if ( is_alt_domain( $_SERVER[‘SERVER_NAME’] ) ) { $domain = str_replace( ‘www.’, ”, $_SERVER[‘SERVER_NAME’] ); define( ‘WP_SITEURL’, ‘http://www.’ . $domain ); define( ‘WP_HOME’, ‘http://www.’ . $domain ); } else if (is_sub_domain( $_SERVER[‘HTTP_HOST’] ) ) { $domain = “{$_SERVER[‘HTTP_HOST’]}”; define( ‘WP_SITEURL’, ‘http://’ . $domain ); define( ‘WP_HOME’, ‘http://’ . $domain ); } else if (! (is_main_domain( … Read more

Elegant way to add parent categories?

wp_set_post_terms() uses wp_set_object_terms(). There is an action hook called set_object_terms which fires on successful setting of an object’s terms. The action hook looks like this do_action ( ‘set_object_terms’, int $object_id, array $terms, array $tt_ids, string $taxonomy, bool $append, array $old_tt_ids ) What we can do here is, inside our action callback function, we can check … Read more

How do I create a way for users to assign categories to a post from the frontend?

I wanted to provide you with a few ideas but once I started I couldn’t stop myself and wrote this little plugin with an obscure name to get you started. <?php /* Plugin Name: WPSE Crowded Cats Plugin URI: http://wordpress.stackexchange.com/questions/43419/how-do-i-create-a-way-for-users-to-assign-categories-to-a-post-from-the-frontend Description: Allow visitors to change categories of posts. Ready to use with custom taxonomies and … Read more

Add forward slash on categories url (serve one version of a url)

Filter category_link so WordPress creates slashed URLs for categories, and redirect_canonical so it accepts those URLs: add_filter( ‘category_link’, ‘wpse_71666_trailingslash_cat_url’ ); add_filter( ‘redirect_canonical’, ‘wpse_71666_trailingslash_cat_url’, 20, 2 ); function wpse_71666_trailingslash_cat_url( $url, $request=”” ) { if ( ‘category_link’ === current_filter() ) return rtrim( $url, “https://wordpress.stackexchange.com/” ) . “https://wordpress.stackexchange.com/”; if ( “$url/” === $request and is_category() ) return $request; … Read more

Woocommerce product categories order [closed]

Woocommerce stores ‘order’ metakeys in the table wp_woocommerce_termmeta. The mechanism it uses is the same as menu_order for posts. Something like this should work: $terms = get_terms(‘product_cat’); //sort $terms somehow $i = -1; foreach ($terms as $term) { $i++; update_woocommerce_term_meta( $term->id, ‘order’, $i); } The same procedure can be used to sort other Woocommerce taxonomies … Read more

Exclude categories from Loop, queries, widgets, post navigation

Excluding categories with pre_get_posts() I found that excluding a category via pre_get_posts() and set_query_var() would work fine except for widgets. The Recent Post Widget would only exclude the category when using $query->set() instead. <?php /** * Does NOT apply to the Recent Posts widget. */ function glck1403271109_exclude_categories( $query ) { $excluded = array( ‘1’, ‘2’ … Read more