Display category posts grouped by taxonomy

I’ve found a solution! <?php // Get current Category $get_current_cat = get_term_by(‘name’, single_cat_title(”,false), ‘category’); $current_cat = $get_current_cat->term_id; // List posts by the terms for a custom taxonomy of any post type $post_type=”myposttype”; $tax = ‘mytaxonomy’; $tax_terms = get_terms( $tax, ‘orderby=name&order=ASC’); if ($tax_terms) { foreach ($tax_terms as $tax_term) { $args = array( ‘post_type’ => $post_type, “$tax” … Read more

Query users by custom taxonomy and user role

Apparently there is no core implementation of ‘tax_query’ in WP_User_Query yet. Check the ticket here for more info –> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an alternative way using get_objects_in_term $taxonomy = ‘shop-category’; $users = get_objects_in_term( $term_id, $taxonomy ); if(!empty($users)){ // WP_User_Query arguments $args = array ( ‘role’ => ‘shop_manager’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘include’ … Read more

Can’t get a custom template taxonomy page to display

I found this code; function ftc_flush_rewrites() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function ftc_add_rewrites() { global $wp_rewrite; $ftc_new_non_wp_rules = array( ‘find/(this)’ => ‘/addit.php?here=$1’, ); $wp_rewrite->non_wp_rules = $ftc_new_non_wp_rules + $wp_rewrite->non_wp_rules; } add_action(‘generate_rewrite_rules’, ‘ftc_add_rewrites’); add_action(‘admin_init’, ‘ftc_flush_rewrites’); in this thread http://wordpress.org/support/topic/writing-wp_rewrite-gtnon_wp_rules-to-htaccess …not sure if that addresses the problem but good luck!

Custom taxonomies capabilities

Just like CPT capabilities those of taxonomy are also customizable, in register_taxonomy(): capabilities ‘manage_terms’ – ‘manage_categories’ ‘edit_terms’ – ‘manage_categories’ ‘delete_terms’ – ‘manage_categories’ ‘assign_terms’ – ‘edit_posts’ Since your authors only have edit_posts it works as you observe — they can assign existing terms, but not create them. You can customize capabilities for taxonomy in question and … Read more

Using pre_get_posts to rewrite search query to display posts from multiple taxonomies

It does’t work because you can’t use set to change all query vars. Simplest way to do the trick is set ‘s’ to an empty string: add_action( ‘pre_get_posts’, function( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $taxquery = array( … ); $query->set( ‘tax_query’, $taxquery ); $query->set(‘s’, ” ); } … Read more

get_term_children for immediate children only (not grandchildren)

Use the get_terms() function instead: $term_children = get_terms( ‘mytaxname’, array( ‘parent’ => get_queried_object_id(), ) ); if ( ! is_wp_error( $terms ) ) { foreach ( $term_children as $child ) { echo ‘ <div class=”product-archive”> <div class=”post-title”> <h3 class=”product-name”><a href=”‘ . get_term_link( $child ) . ‘”>’ . $child->name . ‘</a></h3> </div> </div> ‘; } } get_terms() … Read more

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