Retrieve only terms that are in use

Started researching term arrays and came up with something that works, the solution for creating a conditional based on whether or not a term is in use by any post: <?php $categories = get_categories(‘taxonomy=listing-neighborhood&post_type=listings’); ?> <?php $term_name = wp_list_pluck( $categories, ‘name’ ); $this_name=”Open House”; if( in_array( $this_name, $term_name ) ){ echo ‘<option value=””>Select status or … Read more

Using same term for slug and category

OK, found it. it is possible to have the same slug for a page and a category name. The problem was that someone installed a “redirection” plugin that caused the problems. Lesson learned is to restrict the capabilities of people working on the website, so that they cannot install plugins..

Is it possible to get_terms by taxonomy AND post_type?

Here is another way to do something similar, with one SQL query: static public function get_terms_by_post_type( $taxonomies, $post_types ) { global $wpdb; $query = $wpdb->prepare( “SELECT t.*, COUNT(*) from $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->posts AS p … Read more

Overriding an existing filter

This is the pattern for a filter. Applying/using a filter on something: $filtered_version = apply_filters( ‘the name of the filter’, $the_thing_being_filtered ); This is how you use a filter to modify something: add_filter( ‘the name of the filter’, ‘name_of_a_function_that_will_modify_the_thing_being_filtered’ ); function name_of_a_function_that_will_modify_the_thing_being_filtered( $the_thing_being_filtered ) { // modify $the_thing_being_filtered here return $the_thing_being_filtered; } So in your … Read more