• Resolved masterbip

    (@masterbip)


    This is driving me crazy.
    With this code I can get all my terms in tax “categoria-proyecto” with the correct image

    <?php
            $taxonomy = 'categoria-proyecto';
            $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => $taxonomy) );
            foreach( (array) $terms as $term) {
            echo '<div class="col-1-4"><div class="content">';
            echo '<a href="'.esc_attr(get_term_link($term, $taxonomy)).'" class="redondeado">';
            echo wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' );
            echo '<span>'.$term->name.'</span></a></div></div>';
            }
            ?>

    but with this variation to get first 4 I simply CANT get the image, empty space and no image tag or url …

    <?php
            $taxonomies = 'categoria-proyecto';
            $args = array(
    			'orderby' => rand,
    			'number' => '4'
            );
            $terms = get_terms( $taxonomies, $args );
            if ( !empty( $terms ) && !is_wp_error( $terms ) ){
            foreach( (array) $terms as $term) {
    			echo '<div class="col-1-4"><div class="content">';
    			echo '<a href="'.esc_attr(get_term_link($term, $taxonomy)).'" class="redondeado">';
    			echo wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' );
    			echo '<span>'.$term->name.'</span></a></div></div>';
            }
            };
            ?>

    Can Anybody help me please????

    https://www.ads-software.com/plugins/taxonomy-images/

Viewing 1 replies (of 1 total)
  • Thread Starter masterbip

    (@masterbip)

    YES!°
    Find the answer by myself and also with random!!!

    <?php
    //display random sorted list of terms in a given taxonomy
    $counter = 0;
    $max = 4; //number of categories to display
    $taxonomy = 'categoria-proyecto';
    $terms = get_terms($taxonomy);
    shuffle ($terms);
    //echo 'shuffled';
    if ($terms) {
    	foreach($terms as $term) {
    		$counter++;
    		if ($counter <= $max) {
    			echo '<div class="col-1-4"><div class="content">';
    			echo '<a href="'.esc_attr(get_term_link($term, $taxonomy)).'" class="redondeado">';
    			apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => $taxonomy) );
    			echo wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' );
    			echo '<span>'.$term->name.'</span></a></div></div>';
            }
    	}
    }
    ?>

    That’s it!

Viewing 1 replies (of 1 total)
  • The topic ‘Can't get random 4 terms with images’ is closed to new replies.