Get all categories post is not in

Ok. So, the first bit of code is more correct but it has issues nonetheless. Piece by piece… $categories = get_the_category( $post_id ); $post_id is not set in the code you posted. I assume that value is set earlier in the page somewhere, else that is your first problem. $nocats = get_terms(‘category’, array(‘exclude’ => $categories) … Read more

Weekdays as terms – How to order taxonomy terms by ID in admin panel?

Method #1 – Modifying the query arguments If we want to modify the term order for the schedule_day_taxonomy term checklist, on the single schedule cpt edit screen, then we can use the following setup: add_action( ‘load-post.php’, function() { add_filter( ‘wp_terms_checklist_args’, ‘wpse_terms_checklist_args’ ); } ); function wpse_terms_checklist_args( $args ) { // Target the ‘schedule’ custom post … Read more

term_exists() returning NULL on term that exists

The third argument for term_exists() is an integer, not an array. Parameters $term (integer|string) (required) The term to check Default: None $taxonomy (string) (optional) The taxonomy name to use Default: ” $parent (integer) (optional) $parent ID of parent term under which to confine the exists search Default: 0 Pass the correct arguments and it works. … Read more

Post with certain term and without any term

This should be possible with the tax_query parameters for WP_Query. The query is either for posts where any term NOT EXISTS, OR, for any posts where the term IDs are IN the provided array. ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘group’, ‘operator’ => ‘NOT EXISTS’, ), array( ‘taxonomy’ => ‘group’, ‘field’ => … Read more