Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination".
I have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the villas post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read thisthis post but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count.

$terms = get_terms('countries'); 
if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

  foreach ( $terms as $term ) { 
    $term = sanitize_term( $term, 'countries' ); 
    $term_link = get_term_link( $term, 'countries' ); 

    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
  } 
  echo '</ul>';
}

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination".
I have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the villas post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count.

$terms = get_terms('countries'); 
if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

  foreach ( $terms as $term ) { 
    $term = sanitize_term( $term, 'countries' ); 
    $term_link = get_term_link( $term, 'countries' ); 

    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
  } 
  echo '</ul>';
}

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination".
I have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the villas post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count.

$terms = get_terms('countries'); 
if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

  foreach ( $terms as $term ) { 
    $term = sanitize_term( $term, 'countries' ); 
    $term_link = get_term_link( $term, 'countries' ); 

    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
  } 
  echo '</ul>';
}

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

Show post count number assigned to custom tuxonomytaxonomy

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination". 
I( have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the "villas"villas post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post here on stackexchange but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count. <?php

  $terms = get_terms('countries'); 
  if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

  foreach ( $terms as $term ) { 
    $term = sanitize_term( $term, 'countries' ); 
    $term_link = get_term_link( $term, 'countries' ); 

    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
  } 
  echo '</ul>';
}

?> 

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

Show post count number assigned to custom tuxonomy

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination". I( have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the "villas" post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post here on stackexchange but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count. <?php

  $terms = get_terms('countries'); 
  if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

 foreach ( $terms as $term ) { 
 $term = sanitize_term( $term, 'countries' ); 
 $term_link = get_term_link( $term, 'countries' ); 

   echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
} 
echo '</ul>';
}

?> 

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

Show post count number assigned to custom taxonomy

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination". 
I have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the villas post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count.

$terms = get_terms('countries'); 
if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

  foreach ( $terms as $term ) { 
    $term = sanitize_term( $term, 'countries' ); 
    $term_link = get_term_link( $term, 'countries' ); 

    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
  } 
  echo '</ul>';
}

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.

Source Link
BigDropGR
  • 145
  • 2
  • 10

Show post count number assigned to custom tuxonomy

I'm building a villa rental website, I have two custom post types named "Villa" (used to show villas) and "Destination". I( have installed the CPT-onomies plugin and I use the "Destination" as custom taxonomy for the "villas" post type.

I want on each Destination post (ex. the post showing Greece as destination) to show the number of Villas (posts) assigned to that Destination (custom post type).

I have read this post here on stackexchange but this code is only showing a list of all taxonomies and next to it a number showing the post count.

This is the code showing all the taxonomies and post count. <?php

  $terms = get_terms('countries'); 
  if ( !empty( $terms ) && !is_wp_error( $terms ) ){ 
  echo '<ul>'; 

 foreach ( $terms as $term ) { 
 $term = sanitize_term( $term, 'countries' ); 
 $term_link = get_term_link( $term, 'countries' ); 

   echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name .     '&nbsp;(' . $term->count . ')' . '</a></li>'; 
} 
echo '</ul>';
}

?> 

Thank you for your help. Sorry but English is not my native language I tried to describe my problem best possible.