• Resolved paliomalakas

    (@paliomalakas)


    Hi everyone,

    I’m using WP 4.7.3 along with the photography theme “Tripod”, “Search Everything” and “Media Library Assistant” plugins.
    Everything is working fine, but when searhing for an item the results page is a little off.
    The title in the search results page is fine and everything else, but the images. The first postet image is always the correct one but the following is just the first image posted over and over again.
    See for yourselves:
    Search Results

    Here is the code from the search.php:

    <?php get_header(); ?>
    <?php
        $template = 'search';
    ?>
    
    <section id="main">
        <div class="main-container">    
            <div class="row">
                <div class="twelve columns cat-title">
                    <?php
                        if( have_posts () ){
                    ?>
                            <h2>
                                <span>
                                <?php _e( 'Search results: ' , 'cosmotheme' );  ?>
                                </span>
                            </h2>
                    <?php
                        }else{
                            ?><h2 ><span><?php _e( 'Sorry, no posts found' , 'cosmotheme' ); ?></h2></span><?php
                        }
                    ?> 
                </div>
            </div>
            <?php
                $layout = new LBSidebarResizer( 'search' );
                $layout -> render_frontend();
            ?>
        </div>  
    </section>
    <?php get_footer(); ?>

    and a part of the post.class.php

    static function search(){ 
            /*used for search inputs to search for posts when user types something*/
            
            $query = isset( $_GET['params'] ) ? (array)json_decode( stripslashes( $_GET['params'] )) : exit;
            $query['s'] = isset( $_GET['query'] ) ? $_GET['query'] : exit;
            
            global $wp_query;
            $result = array();
            $result['query'] = $query['s'];
            
            $wp_query = new WP_Query( $query );
            
            if( $wp_query -> have_posts() ){
                foreach( $wp_query -> posts as $post ){
                    $result['suggestions'][] = $post -> post_title;
                    $result['data'][] =  $post -> ID;
                }
            }
            
            echo json_encode( $result );
            exit();
        }

    I really appreciate any help on this, since the theme author does not reply to comments or tickets any more.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    The query seems to be correct, so it looks like there are issues in the template for the loop itself. Can you please provide code for render_frontend() or whatever generates search results items markup?

    Thanks

    Thread Starter paliomalakas

    (@paliomalakas)

    Hi Pavel,
    thanks for your response.
    I’m not quite sure if that is what you mean…here is another snippet of the post.class.php

            static function load_more(){
                $response = array();
                if(isset($_POST['action']) ){
    
                    $id = $_POST[ 'id' ];
                    $row_id = $_POST[ 'row_id' ];
                    $template_id = $_POST[ 'template_id' ];
    
                    $all_templates = get_option( 'templates' );
                    $data = $all_templates[$template_id];
    
                    $template = new LBTemplate( $data );
                    $element = $template -> rows[ $row_id ] -> elements[ $id ];
    
                    $is_ajax = true;
    
                    $nonce = $_POST['getMoreNonce'];
    
                    // check to see if the submitted nonce matches with the
                    // generated nonce we created earlier
                    if ( ! wp_verify_nonce( $nonce, 'myajax-getMore-nonce' ) )
                        die ( 'Busted! Wrong Nonce');
    
                    /*Done with check, now let's do some real work*/
    
                    $element -> view = $_POST['view']; 
                    $element -> carousel = 'no'; 
                    $element ->  paged = $_POST['current_page'] + 1;
                    $element ->  is_ajax = true;
    
                    
                    $type = $_POST['type'];
                    global $wp_query;
                    ob_start();
                    ob_clean();
                    if( $element -> row -> is_additional ){
                        $element -> restore_query();
                        $element -> render_frontend_posts( $wp_query -> posts );
                    }else{
                        call_user_func( array ( $element, "render_frontend_$type" ) );
                    }
                    $content = ob_get_clean();
                    $response['content'] = $content;
                    $response['current_page'] = $element ->  paged;
                    $response['need_load_more'] = ( $wp_query -> query_vars[ 'paged' ] < $wp_query -> max_num_pages );
                    wp_reset_query();
                }
    
                echo json_encode($response);
                exit;    
            }
    Thread Starter paliomalakas

    (@paliomalakas)

    maybe this?

    /*generates content for gallery slider when 'clasic' or 'folio' mode is set*/
            static function get_post_gallery_slide($post_id, $size="gallery_format_slider"){
    
                /*check the meta data where the attached image ids are stored*/
                if ( metadata_exists( 'post', $post_id, '_post_image_gallery' ) ) {
    
                    $product_image_gallery = get_post_meta( $post_id, '_post_image_gallery', true );
    
                    $img_id_array = array_filter( explode( ',', $product_image_gallery ) );
                }else{
                    //backward compatibility with version prev to 1.1
                    $attachet_gallery_ids = meta::get_meta( $post_id, 'imagesattached' );
    
                    if(isset($attachet_gallery_ids['img_ids']) && strlen($attachet_gallery_ids['img_ids'])){
                        /*mata is stored as a string of numbers separated by comma (ex: 909,914,913,912,911,910,908)*/
                        $img_id_array =  explode(',', $attachet_gallery_ids['img_ids']);  //create an array from the string
    
                        
                    }
                }
    
                
                if(isset($img_id_array) && is_array($img_id_array)){
                    foreach ($img_id_array as $value) {
                        $attachments[$value] = $value; // create attachments array in hte format that will work for us                    
                    }
                }
    
                if(!isset($attachments)){ // if no meta is attached to the post then the gallery wil be created from attached images
                    $attachments = get_children(array('post_parent' => $post_id,
                            'post_status' => 'inherit',
                            'post_type' => 'attachment',
                            'post_mime_type' => 'image',
                            'order' => 'ASC',
                            'orderby' => 'menu_order ID'));    
                }
                
                
                if(count($attachments) > 0){
    
                    $settings = meta::get_meta( $post_id , 'settings' );
    
                    $meta = meta::get_meta( $post_id , 'gallerytype') ;
    
                    if ('yes' == $meta['show_slide_btn']) {
                        self::show_gallery_slideshow($attachments);
                    }
    
                    if ('yes' == $meta['show_slide_btn']) { ?>
                        <div id="show-gal-slideshow" class="icon-play shake animated"></div>
                    <?php 
                    }  
    
                    if( options::logic( 'blog_post' , 'enb_lightbox' ) ){ ?>
                        <div class="zoom-image hiddenq">
                            <a href="#" data-rel="prettyPhoto[123]" title="title">&nbsp;</a>
                        </div>
                    <?php } ?>                  
                <div id="galleria">
    Thread Starter paliomalakas

    (@paliomalakas)

    Alright I got it to work without touching the code.
    I simply added a featured image to every single image which resolved my issue. Thanks for helping.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search results in posting same image over and over’ is closed to new replies.