Where/how are categories stored?

There is extensive documentation on the database structure of WordPress in the Codex. Its pretty simple but still you probably do not want to mess with the data directly. As you mentioned CLI I’d recommend WP-CLI which offers some commands you need. A quick example from the docs to change the name of the term … Read more

How do I use the same post slug for different Categories?

Using Parent-Child Page (Recommended) If you don’t have to have categories & posts, then this can be easily achieved using parent-child pages (not posts). For example, say you have three pages like: www.example.com/category-one/ www.example.com/category-two/ www.example.com/category-three/ Now you can have child pages for the above pages with slug email, e.g. www.example.com/category-one/email www.example.com/category-two/email www.example.com/category-three/email This is possible … Read more

Multisite – Protect categories from deletion?

Extending @Roman’s answer. The following was developed and tested in a Multisite environment – local and live WP installs. Looking at the source of wp_delete_term, there are some hooks that are triggered when the function is called. I’m not sure if this is the best way of doing this, but it works. add_action( ‘delete_term_taxonomy’, ‘wpse_70758_del_tax’, … Read more

Group WP_Query by category

You could look at modifying the WP_Query with a SQL command to group them, but that’s a bit beyond my current MySQL, however, I’ve always done it by running a foreach on the taxonomy itself with this http://codex.wordpress.org/Function_Reference/get_categories Here’s some sample code: <?php global $post; $current = get_the_ID($post->ID); $cargs = array( ‘child_of’ => 0, ‘orderby’ … Read more

How to get posts from two categories with WP_Query?

In my experience using ‘posts_*’ filters (‘posts_request’, ‘posts_where’…) in combination with str_replace / preg_replace is unreliable and unflexible: Unreliable because if another filter modify uses one of that filters, in better case one gets unexpected results, in worst cases one gets SQL errors. Unflexible because changing an argument, e.g. ‘include_children’ for categories, or reuse the … Read more

is_category() in pre_get_posts strange error

After a bit of investigation… If you pass a category to is_category it uses get_queried_object to grab data– see the source. get_queried_object returns NULL for categories that do not exist. You can demonstrate that with: function custom_posts_per_page($query) { var_dump(get_queried_object()); } add_filter( ‘pre_get_posts’, ‘custom_posts_per_page’ ); Load a valid category archive and then an invalid one. The … Read more