Get terms of posts with category with sql

Here’s the solution: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN {$wpdb->prefix}term_taxonomy cats_tax ON (cats_rel.term_taxonomy_id = cats_tax.term_taxonomy_id) … Read more

Nice URLs for a Custom Post Type List with a Shared Custom Taxonomy?

For the first preference, you’d need to filter in additional rewrite rules like so; function __extra_country_rewrite_rules( $rules ) { global $wp_rewrite; if ( !isset( $wp_rewrite ) ) $wp_rewrite = new WP_Rewrite; $m1 = $wp_rewrite->preg_index(1); // preg match backreferences $m2 = $wp_rewrite->preg_index(2); $m3 = $wp_rewrite->preg_index(3); $rules[‘country/([^/]+)/([^/]+)s/feed/(feed|rdf|rss|rss2|atom)/?$’] = “index.php?country=$m1&post_type=$m2&feed=$m3”; $rules[‘country/([^/]+)/([^/]+)s/(feed|rdf|rss|rss2|atom)/?$’] = “index.php?country=$m1&post_type=$m2&feed=$m3”; $rules[‘country/([^/]+)/([^/]+)s/page/?([0-9]{1,})/?$’] = “index.php?country=$m1&post_type=$m2&paged=$m3”; $rules[‘country/([^/]+)/([^/]+)s/?$’] = … Read more

How can I set a default listing order on the admin page for a custom taxonomy? (without plugins)

You need to take a look at /core_root/wp-admin/includes/class-wp-terms-list-table.php and then add an extended class and make use of the WP_list_Table Class and documentation. basically you’re overriding the order and orderby in some custom plugin. Btw: “No Plugins” is never a good idea as plugins may show you how it works in code and therefore be … Read more

How to assign default taxonomy to pages on ‘save_post’?

You are using wp_set_object_terms wrong, the second parameter should be the term slug or id and the 3 parameter should be the taxonomy name, so try: function set_default_object_terms( $id, $post ) { if ( ‘publish’ === $post->post_status ) { log_me (‘be in function while “publish” i pressed with this id: ‘.$id); $taxonomy_ar = get_terms( ‘property-features’ … Read more

Custom Taxonomy Meta Admin Column

I managed to work it out. Seems like the filters only work when wrapped in an ‘admin_init’ action. My final code to add an admin column for the custom taxonomy meta ‘front_page’ to the custom taxonomy ‘shopp_department’ in my themes’ functions.php // Register the column function department_add_dynamic_hooks() { $taxonomy = ‘shopp_department’; add_filter( ‘manage_’ . $taxonomy … Read more