Custom Taxonomy is Missing (Or Limiting) Items

I created a custom taxonomy; "places" using toolset

region>country>city with 12 Regions / All Countries and just a few cities; 12 parents, 260 children

Where I am using the taxonomy in a post, custom post type or the menu, only some of the items show and it is quite random. 1/2 of Europe shows up 3 from the Caribbean, etc

I used the plugin Toolset; this issue has repeated in 4 different installs. I have worked with hosting and they assure me it is a development issue. I have worked with toolset and am on Day 6 of no solution; I have tried with different themes (Hello & Astra), Using Elementor or not (no plugins other than toolset itself; there is no support over the weekend. Does anyone have any idea WHY I would be missing just some of the taxonomy?

I am not seeing any errors in debugging

Sort the result of the main Query in shop page by a custom taxonomy

In a WooCommerce site, we have products that have a custom taxonomy that are assign to a region.

When the user visits the site, we activate the browser geolocation, and we assign the user a region in a cookie.

Now we would like to show, in the shop page and in the product_cat taxonmies, in first the products that are assign to the same region of the user and then all other regions.

How could we implement this ?

So far, I taught of using pre_get_posts, and using something like :

add_action('pre_get_posts', 'order_by_region', 999999); function order_by_region($  q){  if(!is_admin() && $  q->is_main_query() && (is_shop() || is_tax('product_cat'))){   $  q->set('orderby', 'meta_value');   $  q->set('order', 'DESC');   $  q->set('value', $  _COOKIE['nameofusercookie']);   $  q->set('meta_key', 'regions');   }   return $  q; } 

But this didn’t work. I just found that in there it will filter the posts instead of ordering by regions.

I found the ‘the_posts’ hook. That contains all the products after quering but not yet looped. I think it might be better place to sort all the products with the cookie. But how do i compare the cookie and the regions taxonomy in each products ?

add_filter('the_posts', 'sort_query_by_region', 10, 2); function sort_query_by_region($  posts, $  q){  $  cookie = $  _COOKIE['selected_region'];   if(isset($  cookie) && !empty($  cookie)){   if(!is_admin() && $  q->is_main_query() && (is_shop() || is_tax('product_cat'))){    $  posts = sortByRegion($  posts);   }  }  return $  posts; }  function sortByRegion($  posts){  usort($  posts, "regionOrder");  return $  posts; }  function regionOrder($  a, $  b) {    // get the cookie    $  cookie = $  _COOKIE['slected_region'];    // Get the term region of each compared product   $  regionA = get_the_terms($  a->ID, 'regions')[0]->slug;   $  regionB = get_the_terms($  b->ID, 'regions')[0]->slug;    if($  regionA != $  cookie || $  regionB != $  cookie){    return ($  a, $  b);   } else {    return $  a < $  b;   } } 

I must that either doesn’t work.

Anyone everdone such a re-ordering and knows I to help me?

Show content/template for the /tag/ or /taxonomy/ part of the URL in WordPress

Heu,

I’ve been trying to figure this problem out but can’t quite find an answer.

On my WordPress site, the URL for tags is mysite.com/tag/tag-term. This displays fine using the tag.php template. However, If I just go to mysite.com/tag/ I get a 404 error. It is the same for custom taxonomies I have. For example, I have custom taxonomy of developer so if I goto mysite.com/developer/term it loads content under that term using taxonomy-developer.php template. But going to mysite.com/developer/ returns a 404.

Is there a template I can use, or some other method to get WordPress to display a list of terms if someone goes to the /tag/ or /taxonomy/ part of the URL?

Thanks

Custom Post Type / Taxonomy not displaying archive

I am trying to use the Atreas Theme: https://wordpress.org/themes/antreas/

This is the site I am working on: https://sandbox.paediatricphysiotherapyassociates.com/

All I want is an archive page for my Team Members to display them all in one spot. I tried adding: 'has_archive' => true' to the plugin php files directly “cpost-team.php” but I can’t for the life of me find the url for the archive page for Team Members. Either that or I’m missing something else. This is the direct code for this “Custom Posts” (aka Team Members) plugin:

<?php  //Define team post type add_action( 'init', 'cpo_cpost_team' ); function cpo_cpost_team() {    $  show_ui = false;    if ( defined( 'CPOTHEME_USE_TEAM' ) || cpo_get_option( 'display_team' ) ) {        $  show_ui = true;    }    $  labels = array(        'name'               => __( 'Team Members', 'cpo-companion' ),        'singular_name'      => __( 'Team Member', 'cpo-companion' ),        'add_new'            => __( 'Add Team Member', 'cpo-companion' ),        'add_new_item'       => __( 'Add New Team Member', 'cpo-companion' ),        'edit_item'          => __( 'Edit Team Member', 'cpo-companion' ),        'new_item'           => __( 'New Team Member', 'cpo-companion' ),        'view_item'          => __( 'View Team Member', 'cpo-companion' ),        'search_items'       => __( 'Search Team Members', 'cpo-companion' ),        'not_found'          => __( 'No team members found.', 'cpo-companion' ),        'not_found_in_trash' => __( 'No team members found in the trash.', 'cpo-companion' ),        'parent_item_colon'  => '',    );     $  member_slug = cpo_get_option( 'slug_team_member' );    if ( '' == $  member_slug ) {        $  member_slug = 'cpo_team';    }     $  fields = array(        'labels'              => $  labels,        'public'              => true,        'publicly_queryable'  => true,        'exclude_from_search' => true,        'show_ui'             => $  show_ui,        'query_var'           => true,        'rewrite'             => array( 'slug' => apply_filters( 'cpotheme_slug_team_member', $  member_slug ) ),        'capability_type'     => 'page',        'hierarchical'        => false,        'menu_icon'           => 'dashicons-universal-access',        'menu_position'       => null,        'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ),    );     register_post_type( 'cpo_team', $  fields );  }   //Define admin columns in team post type add_filter( 'manage_edit-cpo_team_columns', 'cpo_cpost_team_columns' ); if ( ! function_exists( 'cpo_cpost_team_columns' ) ) {    function cpo_cpost_team_columns( $  columns ) {        $  columns = array(            'cb'             => '<input type="checkbox" />',            'ctct-image'     => __( 'Image', 'cpo-companion' ),            'title'          => __( 'Title', 'cpo-companion' ),            'ctct-team-cats' => __( 'Groups', 'cpo-companion' ),            'date'           => __( 'Date', 'cpo-companion' ),            'author'         => __( 'Author', 'cpo-companion' ),        );        return $  columns;    } }  //Define team category taxonomy add_action( 'init', 'cpo_tax_teamcategory' ); if ( ! function_exists( 'cpo_tax_teamcategory' ) ) {    function cpo_tax_teamcategory() {        $  labels = array(            'name'               => __( 'Member Groups', 'cpo-companion' ),            'singular_name'      => __( 'Member Group', 'cpo-companion' ),            'add_new'            => __( 'New Member Group', 'cpo-companion' ),            'add_new_item'       => __( 'Add Member Group', 'cpo-companion' ),            'edit_item'          => __( 'Edit Member Group', 'cpo-companion' ),            'new_item'           => __( 'New Member Group', 'cpo-companion' ),            'view_item'          => __( 'View Member Group', 'cpo-companion' ),            'search_items'       => __( 'Search Member Groups', 'cpo-companion' ),            'not_found'          => __( 'No member groups were found.', 'cpo-companion' ),            'not_found_in_trash' => __( 'No member groups were found in the trash.', 'cpo-companion' ),            'parent_item_colon'  => '',        );         $  slug = cpo_get_option( 'slug_team_category' );        if ( '' == $  slug ) {            $  slug = 'team-group';        }        $  fields = array(            'labels'            => $  labels,            'public'            => true,            'show_ui'           => true,            'show_in_nav_menus' => true,            'show_tagcloud'     => false,            'rewrite'           => array( 'slug' => apply_filters( 'cpotheme_slug_team_category', $  slug ) ),            'hierarchical'      => true,        );         register_taxonomy( 'cpo_team_category', 'cpo_team', $  fields );    } } 

Also based on the code what should the url outcome be? I assumed it should be on: https://sandbox.paediatricphysiotherapyassociates.com/cpo_team/

Additionally my custom taxonomy for team members (groups) is not displaying posts that fall under the given group: https://sandbox.paediatricphysiotherapyassociates.com/?cpo_team_category=ba enter image description here

Sorry I’m not great with php. Thank you in advance!!

Get/create the parent taxonomy by using shortcode in woocommerce?

How would I get/create the parent taxonomy by using shortcode in woocommerce?

My product categories should be like:

– Food

— Fruits

— Healthy Fruits
— Organic Fruits

— Meat

— Pork
— Lamb
— Beef

For example, I would like to display “Fruits” when user at the “Healthy Fruits” product archive page.

Hierarchical taxonomy list with transformated links

I have two functions displaying a term list of the selected taxonomy:

First function:

$  terms = get_the_terms(get_the_ID(), 'MY_TAXONOMY'); if (!is_wp_error($  terms) && !empty($  terms)) {     foreach ($  terms AS $  term) {         $  name = $  term->name;         $  link = add_query_arg('fwp_typ', FWP()->helper->safe_value($  term->slug), 'https://www.MYWEBSITE.com/');         echo "<a href='$  link'>$  name</a><br />";     } }        

Second function:

    global $  post;     $  taxonomy = 'MY_TAXONOMY';     $  terms = wp_get_post_terms( $  post->ID, $  taxonomy, array( "fields" => "ids" ) );     if( $  terms ) {         echo '<?ul>';         $  terms = trim( implode( ',', (array) $  terms ), ' ,' );         wp_list_categories( 'title_li=&taxonomy=' . $  taxonomy . '&include=' . $  terms );         echo '<?/ul>';     }  

The first one ignores the hierarchy, but transforms the links as I need, i.e. so that they lead to queries of the WP’s Facet Plugin. I understand that this line is key here:

$  link = add_query_arg('fwp_typ', FWP()->helper->safe_value($  term->slug), 'https://www.MYWEBSITE.com/');  

The second one includes the hierarchy, but the links don’t lead where I would like. How do I make this second function transform links like the first one?

Create Post Query to order by a Taxonomy custom meta field

I have a standard WP_Query to search for Posts of a certain Custom Post Type. I am trying to extend this by filtering by a specific custom meta field that was set for a Taxonomy that is attached to the Post.

What I’ve done is created a Taxonomy, and in that Tax I’ve added a custom meta field called “sorting_weight” that is a numerical field. So when admin assign a CPT to this Tax, I would be able to query all CPT entries and then orderly that numerical field.

All the tutorials online are getting confused and thinking the user wants to sort by normal post custom meta. This is not what I want – I want to sort by the CPT’s Taxonomy’s custom meta.

From what I can gather, I can’t even pipe this logic into a normal WP_Query argument? If so, how would I refactor my code to order by this Taxonomy custom meta field “sorting_weight”?

The below shows the general query I am using:

     /**      * @return array      */     protected function returnQuery(): array     {         $  query = [             'post_type' => $  this->getPostTypeName(),             'show_posts' => -1,             'hide_empty' =>  true,             'meta_key' => 'year',             'orderby' => 'meta_value',             'order' => 'DESC'         ];          /**          * CPT Meta Queries          */         if ($  this->getSearchQuery()['appGallerySearch_Category']) {             $  query['meta_query'][] = [                 'key' => 'topic',                 'value' => $  this->getSearchQuery()['appGallerySearch_Category'],                 'compare' => 'LIKE'             ];         }         if ($  this->getSearchQuery()['appGallerySearch_Program']) {             $  query['meta_query'][] = [                 'key' => 'program',                 'value' => $  this->getSearchQuery()['appGallerySearch_Program'],                 'compare' => 'LIKE'             ];         }         if ($  this->getSearchQuery()['appGallerySearch_Division']) {             $  query['meta_query'][] = [                 'key' => 'divisions',                 'value' => $  this->getSearchQuery()['appGallerySearch_Division'],                 'compare' => 'LIKE'             ];         }         if ($  this->getSearchQuery()['appGallerySearch_Year']) {             $  query['meta_query'][] = [                 'key' => 'year',                 'value' => $  this->getSearchQuery()['appGallerySearch_Year'],                 'compare' => 'LIKE'             ];         }         if ($  this->getSearchQuery()['appGallerySearch_Location']) {             $  query['meta_query'][] = [                 'key' => 'region',                 'value' => $  this->getSearchQuery()['appGallerySearch_Location'],                 'compare' => 'LIKE'             ];         }         if ($  this->getSearchQuery()['appGallerySearch_Keyword']) {             $  query['meta_query'][] = [                 'key' => 'description',                 'value' => $  this->getSearchQuery()['appGallerySearch_Keyword'],                 'compare' => 'LIKE'             ];         }          return $  query;     } 

Display list of posts from taxonomy term, but display the latest post featured image

I’m trying to do a page where all posts from a custom post type list, divided by their taxonomy terms and having a big photo on top of the list (latest featured image from said term). Right now I have the following code, but it displays the wrong images (each term should show latest post’s featured image, and I’m not even sure why the images are just random, even in the wrong term):

<section id="" class="">  <?php      }     wp_reset_query();   $  tax = 'technology-category';      $  terms = get_terms( $  tax ,array(          'orderby'    => 'ID',         'order'      => 'ASC',         'hide_empty' => 0,     ));      //Loop throug each taxonomy terms,      foreach ( $  terms as $  term ) {          //Query argument for post     $  args = array(              'post_type' => 'technology', // Or Custom Post Type,              'order' => 'DESC',              'orderby' => 'date',             'taxonomy' => $  tax,             'term' => $  term->slug, // Query posts for each term based on term slug         );         $  query = new WP_Query( $  args );          $  posts = $  query->get_posts();          ?>  <div class="container-fluid tech-cat-item py-5">     <div class="container">     <div class="row align-items-center pb-3">     <div class="col-1">     <img class="img-fluid" src="<?php echo z_taxonomy_image_url($  term->term_id); ?>"> </div> <div class="col-11">     <h3><?php echo $  term->name;?></h3> </div> </div> <?php //Do query to get image?        $  ga_item = array(             'post_type' => 'technology',               'order' => 'DESC',              'orderby' => 'date',             'taxonomy' => $  tax,             'term' => $  term->slug,              'posts_per_page' => '1', //just one because only need the latest post's featured image );        $  ga_query = new WP_Query( $  ga_item );         $  ga_posts = $  query->get_posts();     if ( $  ga_query->have_posts() ) {     while ( $  ga_query->have_posts() ) { $  ga_query->the_post(); ?>     <div class="row ga-panel py-5">     <div class="col-12">         <?php          $  ga_url = get_the_post_thumbnail_url($  post->ID,'full'); ?>         <img class="img-fluid ga-img" src="<?php echo esc_url($  ga_url);?>">     </div>     </div> <?php } } wp_reset_query(); ?>     <div class="row">         <?php          if ( $  posts ) {          foreach ( $  posts as $  post ) { ?>              <div class="col-4 ga-links">                 <a href="<?php the_permalink( $  post->ID ); ?>" data-swap="<?php echo esc_url($  ga_url);?>" > <?php echo $  post->post_title; ?></a>             </div>          <?php                     }         }        ?> </div> </div> </div>   <?php  }  wp_reset_query(); ?>                      </section> 

Potential Security Issue in Custom Taxonomy Search Functionality

I’m wishing to add some functionality to a client WordPress site that allows you to include taxonomy terms from custom post types in the WordPress search, and come across the following answer:

Include custom taxonomy term in search

This solution does work, but in the comments a user has mentioned that it’s “probably not a good idea to inject the raw publicly available search string directly into an SQL query.” and added a link for further reading. I can’t see anything in this link that relates to the specifices of the answer though.

For quick reference the code for the answer is below, would this code be a security risk? And if so what would the solution be so you can still have the functionality of being able to include taxonomy terms in the WP search without the security risk?

Many thanks

// search all taxonomies, based on: http://projects.jesseheap.com/all-projects/wordpress-plugin-tag-search-in-wordpress-23  function atom_search_where($  where){ global $  wpdb; if (is_search())     $  where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$  wpdb->posts}.post_status = 'publish')"; return $  where; }  function atom_search_join($  join){ global $  wpdb; if (is_search())     $  join .= "LEFT JOIN {$  wpdb->term_relationships} tr ON {$  wpdb->posts}.ID = tr.object_id INNER JOIN {$  wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$  wpdb->terms} t ON t.term_id = tt.term_id"; return $  join; }  function atom_search_groupby($  groupby){ global $  wpdb;  // we need to group on post ID $  groupby_id = "{$  wpdb->posts}.ID"; if(!is_search() || strpos($  groupby, $  groupby_id) !== false) return $  groupby;  // groupby was empty, use ours if(!strlen(trim($  groupby))) return $  groupby_id;  // wasn't empty, append ours return $  groupby.", ".$  groupby_id; }  add_filter('posts_where','atom_search_where'); add_filter('posts_join', 'atom_search_join'); add_filter('posts_groupby', 'atom_search_groupby');