Support » Plugin: Taxonomy Images » Display all terms within a taxonomy (with images) sorted by date of posts.

  • chriddell

    (@chriddell)


    Hi,

    I’m trying to display a list of all terms within a given taxonomy (name, number of posts associated & image).

    I’m having trouble getting the plugin to display images correctly. I currently have this code working, but without images.

    $terms = get_terms( 'f3s_collections', array( 'orderby' => 'post_date', 'order' => 'DESC' ) );
    
      foreach($terms as $term) {
        echo '<div class="collection">' . wp_get_attachment_image( $term->image_id, 'f3s_collections' ) .
      '<div class="collection__container">
      <h3 class="collection__title">
      <a href="' . esc_url( get_term_link($term, $term->taxonomy)) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name) . '">' . $term->name . '</a>
      </h3>
      <p class="collection__count icon icon--collection">' . $term->count . ' items in this collection</p>
      </div></div>';
      }

    Anyone have any ideas how I can get the images to work correctly?

    Chris

    https://wordpress.org/plugins/taxonomy-images/

Viewing 1 replies (of 1 total)
  • chriddell

    (@chriddell)

    I have a custom function which allows me to order by date. See below:

    function wpse147412_order_terms_by_post_date( $pieces, $taxonomies, $args ) {
      global $wpdb;
    
      if ( 'post_date' !== $args['orderby'] ) {
        return $pieces;
      }
    
      $args = wp_parse_args( $args, array( 'post_types' => 'post' ) );
    
      $pieces['fields']   = 'DISTINCT ' . $pieces['fields'];
      $pieces['join']    .= " JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id";
      $pieces['join']    .= " JOIN $wpdb->posts AS p ON p.ID = tr.object_id";
      $pieces['where']   .= " AND p.post_type IN ('" . implode( "', '", (array) $args['post_types'] ) . "')";
      $pieces['orderby']  = 'ORDER BY p.post_date';
    
      return $pieces;
    }
    add_filter( 'terms_clauses', 'wpse147412_order_terms_by_post_date', 10, 3 );
Viewing 1 replies (of 1 total)
  • The topic ‘Display all terms within a taxonomy (with images) sorted by date of posts.’ is closed to new replies.