Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on an image page feature which retrieves the MOST related posts ("image" custom post type). So images with most terms in common should be listed first. But this does not seem to be happening in below code....

See this page - its obvious its not working -> http://www.clipartillustrations.com/image/orange-man-barista-or-waiter-with-apron/

<?php
function widget( $args, $instance )
{

    //get current image id
    global $wp_query;

    $post = $wp_query->post;

    $image_ID = $post->ID;

    //outputs the content of the widget

    extract( $args );

    $tags = wp_get_object_terms( $image_ID, 'image-tags' );

    $title = apply_filters( 'widget_title', $instance[ 'title' ] );

    echo $before_widget;

    if ( !empty( $title ) )
        echo $before_title . $title . $after_title;

    //this related images code was derived from here: http://www.wprecipes.com/how-to-show-related-posts-without-a-plugin

    if ( $tags ) {
        $tag_ids = array( );
        foreach ( $tags as $individual_tag )
            $tag_ids[ ] = $individual_tag->term_id;

        $query_args = array(
             'post_type' => 'image',
            'tax_query' => array(
                 array(
                     'taxonomy' => 'image-tags',
                    'field' => 'id',
                    'terms' => $tag_ids 
                ) 
            ),
            'post__not_in' => array(
                 $image_ID 
            ),
            'showposts' => 6 
        );

        $similar_images_query = new wp_query( $query_args );

        if ( $similar_images_query->have_posts() ) {

            while ( $similar_images_query->have_posts() ) {
                $similar_images_query->the_post();
?>

<div class="widget-featured search-result">
    <div class="inner-featured">
        <div class="thumb"> 
        <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">
            <?php
                if ( has_post_thumbnail() ) {
                    the_post_thumbnail();
                }               
            ?>
        </a> </div>
    </div>
</div>
<?php
            }

        }
    }

    echo '<div class="clearfix"></div>';
    echo $after_widget;

}
?>

I'd love to know where I'm going wrong.

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.