Your address will show here +12 34 56 78

Home Forums WP ESTATE – Real Estate WordPress Theme FORUM Show only recent featured properties Reply To: Show only recent featured properties

#30910

Gonzalo

This blog is editing the content, try this!

function recent_posts_pictures($attributes, $content = null) {
    global $options;
    $return_string='';
    $pictures = '';
    $button='';
    $class='';
    $multiline='';
    $rows=1;
    $onlyfeat=$category=$action=$city=$area='';
    global $post;
    
    
    /* by GEAR invent! */
    if ( isset($attributes['only_feat']) ) {
	$onlyfeat=$attributes['only_feat'];
    }
    /* gearinvent.com */

    if ( isset($attributes['category_ids']) ){
       $category=$attributes['category_ids'];
    }

    if ( isset($attributes['action_ids']) ){
       $action=$attributes['action_ids'];
    }

    if ( isset($attributes['city_ids']) ){
       $city=$attributes['city_ids'];
    }

    if ( isset($attributes['area_ids']) ){
       $area=$attributes['area_ids'];
    }
     
     
    if ( isset($attributes['rows']) ){
        $rows=$attributes['rows'];
    }
    
    if($rows>1){
        $multiline='multiline';
    }
    
    $post_number = $attributes['number'];
    if ($post_number > 5)
        $post_number = 5;

    $post_number_total=$post_number*$rows;
    
    if ($attributes['type'] == 'properties') {
        $type = 'estate_property';
        
	$onlyfeat_array =   '';
        $category_array =   '';
        $action_array   =   '';
        $city_array     =   '';
        $area_array     =   '';
        
    
	// build onlyfeat cond
        $onlyfeat_cond = 0;
	if($onlyfeat!=''){
            $onlyfeat_cond = 1;
        }

        // build category array
        if($category!=''){
            $category_of_tax=array();
            $category_of_tax=  explode(',', $category);
            $category_array=array(     
                            'taxonomy'  => 'property_category',
                            'field'     => 'term_id',
                            'terms'     => $category_of_tax
                            );
        }
            
        
        // build action array
        if($action!=''){
            $action_of_tax=array();
            $action_of_tax=  explode(',', $action);
            $action_array=array(     
                            'taxonomy'  => 'property_action_category',
                            'field'     => 'term_id',
                            'terms'     => $action_of_tax
                            );
        }
        
        // build city array
        if($city!=''){
            $city_of_tax=array();
            $city_of_tax=  explode(',', $city);
            $city_array=array(     
                            'taxonomy'  => 'property_city',
                            'field'     => 'term_id',
                            'terms'     => $city_of_tax
                            );
        }
        
        // build city array
        if($area!=''){
            $area_of_tax=array();
            $area_of_tax=  explode(',', $area);
            $area_array=array(     
                            'taxonomy'  => 'property_area',
                            'field'     => 'term_id',
                            'terms'     => $area_of_tax
                            );
        }
        
        
        
        
            $args = array(
                'post_type'         => $type,
                'post_status'       => 'publish',
                'paged'             => 0,
                'posts_per_page'    => $post_number_total,
                'meta_key'          => 'prop_featured',
                'orderby'           => 'meta_value  ',
                'order'             => 'DESC',
                'tax_query'         => array( 
                                        $category_array,
                                        $action_array,
                                        $city_array,
                                        $area_array
                                    )
              
            );
        
       
          
    } else {
        $type = 'post';
        $args = array(
            'post_type'      => $type,
            'post_status'    => 'publish',
            'paged'          => 0,
            'posts_per_page' => $post_number_total,
            'cat'            => $category
        );
    }

    if ($attributes['link'] != '') {
        if ($attributes['type'] == 'properties') {
            $button .= '<div class="listinglink-wrapper"><div class="btn listing listingbut listinglink"><span class="prop_plus">+</span>'.__(' more listings','wpestate').' </div></div>';
        } else {
            $button .= '<div class="listinglink-wrapper"><div class="btn listing listingblog listinglink"><span class="blog_plus">+</span> '.__(' more articles','wpestate').' </div></div>';
        }
    } else {
        $class = "nobutton";
    }

    
    $return_string .= '<div class="article_container bottom-'.$type.' '.$class.'" >';
    


        if ($attributes['type'] == 'properties') {
            add_filter( 'posts_orderby', 'my_order' ); 
            $recent_posts = new WP_Query($args);
            $count = 1;
            remove_filter( 'posts_orderby', 'my_order' ); 
        }else{
            $recent_posts = new WP_Query($args);
            $count = 1;
        }
   
    
    
    
    while ($recent_posts->have_posts()): $recent_posts->the_post();
   
     $featured  = intval  ( get_post_meta($post->ID, 'prop_featured', true) );
     if ($onlyfeat_cond && !$featured) {
	//if only featured selected, hide not featured
     } else {

        if ( $count % $post_number== 0 && $count!=1) {
            $return_string .= '<article class="col  property_listing '.$multiline.' last">';
        } else {
            $return_string .= '<article class="col  property_listing '.$multiline.' ">';
        }
    
        $link      = get_permalink();

        
        // select pictures
        if (has_post_thumbnail()):
            $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_full');
            switch($post_number){
                case 1:
                    break;
                    $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_full');
                case 2:
                    $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_full');
                    break;
                case 3:
                 
                    if ($options['fullwhite']==='fullwhite'){
                        $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_full');
                    }else{
                        $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_listings'); 
                    }
                    break;
                case 4:
                    $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_listings');
                    break;
                case 5:
                     $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_listings');
                    break;
            }
            
           // $tumb_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'property_listings');
            $return_string .= '<figure>thumb';
        endif;
        
        // ribbons
        if($type == 'estate_property'){
            $prop_stat = get_post_meta($post->ID, 'property_status', true);      
            if( $featured==1){
                $return_string .='<div class="featured_div">'.__('Featured','wpestate').'</div>';
            }
            if ($prop_stat != 'normal') {
                $ribbon_class = str_replace(' ', '-', $prop_stat);
                $return_string .='<div class="ribbon-wrapper-default ribbon-wrapper-' . $ribbon_class . '"><div class="ribbon-inside ' . $ribbon_class . '">' . $prop_stat . '</div></div>';
            }
        }
        
        $return_string .= '          
                <figcaption class="figcaption-'.$type.'" data-link="' . $link. '">
                    <span class="fig-icon"></span>                   
                </figcaption>     
            </figure>';

       

        $return_string .= '
        <div class="property_listing_details"> 
        <h3 class="listing_title">' . get_the_title() . ' </h3>';

        if ($attributes['type'] == 'properties') {
            $currency = get_option('wp_estate_currency_symbol', '');
            $where_currency = get_option('wp_estate_where_currency_symbol', '');


            $price = get_post_meta($post->ID, 'property_price', true);
            if ($price != '') {
                $price = number_format($price,2,',','.');

                if ($where_currency == 'before') {
                    $price = $currency . ' ' . $price;
                } else {
                    $price = $price . ' ' . $currency;
                }
            }
            
            $property_address   = get_post_meta($post->ID, 'property_address', true);
            $property_city      = get_the_term_list($post->ID, 'property_city', '', ', ', '');
            $price_label        = esc_html ( get_post_meta($post->ID, 'property_label', true) );
            
            // property
            $return_string .='<span class="property_price">' . $price .' '.$price_label. '</span>';
            $return_string .='<div class="article_property_type">'.$property_address.', '.$property_city.' </div>';

            $return_string .='<div class="article_property_type">'
                              .get_the_term_list($post->ID, 'property_category', '', ', ', '').' '.__('in','wpestate').' '.get_the_term_list($post->ID, 'property_action_category', '', ', ', '').'
                              </div>';
         
            
           
            
        } else {
            $return_string .= '<p class="recent_post_p">' . limit_words(get_the_excerpt(), 14) . ' ...</p>';
        }



        $return_string .= '</div></article>';
        $count++;
     }

    endwhile;

    $return_string .=$button;


    $return_string .= '</div>';
    wp_reset_query();
    return $return_string;
}