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

Change Gutenberg category checkboxes to radios

Fortunately there is a hook that we can use to customize what component is used to render the taxonomy panels called editor.PostTaxonomyType. Gutenberg renders taxonomy panels with a component called PostTaxonomies, which really just checks whether the taxonomy is heirarchical or not, and passes the props along to either the HierarchicalTermSelector or FlatTermSelector components accordingly. … Read more

Fixing category count

If you just want to update the counts of posts in each term, wp_update_term_count_now( $terms, $taxonomy ) should do it… just pass the terms affected as an array and run it once for each taxonomy you have. You can also call wp_defer_term_counting( true ) before inserting new rows, and then after adding your posts, catch … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)