WordPress Search Results for Multiple Post Types

The wp_get_attachment_image_src() function expects you to also pass some kind of attachment ID plus it doesn’t grab the image HTML that we need so instead we should use wp_get_attachment_image(). IF a post has a post thumbnail, grab it.ELSE IF the post has any attached images, grab the first one.ELSE maybe show a placeholder? I’ve defined … Read more

Show one item per category of a custom post type

$args = array( ‘taxonomy’ => ‘portfolio_type’, ‘exclude’ => ‘28,30’, ); $tax = get_terms($args); foreach($tax as $t){ echo ‘<div class=”span3 produto-lista”>’; $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘portfolio_type’, ‘field’ => ‘slug’, ‘terms’ => array($t->slug) ) ), ‘posts_per_page’ => 1, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ); $query = new WP_Query( $args ); while … Read more

code suddenly appearing from my tempate second loop

Are you absolutely certain that you don’t accidentally have a closing php tag where you shouldn’t? – yes – turned out to be that I had <? rather than <?php – probably the new server was set differently – as per https://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags

Cannot display or echo alt text on featured image

I am not so sure of what I am going to say, but from a fast look, $featured_image is an array (URL, width, height, is_intermediate). so assuming that your alternative text exists in this array, you need to specify its index like this: $featured_image[index_of_alt_text] according to my understanding, the $featured_image array doesn’t contain your alternative … Read more

Using foreach loop breaks

I believe your issue is with $vals=get_post_meta($post_id, $key2, true); If you check the codex, the last parameter for get_post_meta is whether to return a single value or array of values. You have set it to true which means return only one value. Try it with false (the default) it should work.