Support

Account

Home Forums General Issues If get_fields is empty not working Reply To: If get_fields is empty not working

  • It comes from a theme that we bought 🙂

    public function render($atts, $content = null) {
            $args = array(
    	        'type'                      => 'gallery',
    	        'number_of_columns'         => '3',
                'space_between_items'       => 'normal',
    	        'number_of_items'           => '-1',
                'category'                  => '',
                'selected_shows'            => '',
    	        'title_tag'                 => 'h5',
    	        'image_proportions'         => 'full',
    	        'enable_fixed_proportions'  => 'no',
    	        'show_category'             => 'no',
    	        'show_date_range'           => 'no',
                'orderby'                   => 'date',
                'order'                     => 'ASC',
    	        'show_single_layout'        => 'info-bellow',
    	        'show_slider'               => 'no',
    	        'slider_navigation'	        => 'no',
    	        'slider_pagination'	        => 'no',
    	        'pagination_type'          => 'standard',
    	        'load_more_top_margin'     => '',
    	        'slider_autoplay'       => 'no'
            );
    		$params = shortcode_atts($args, $atts);
    	
    	    /***
    	     * @params query_results
    	     * @params holder_data
    	     * @params holder_classes
    	     */
    		$additional_params = array();
    	    
    		$query_array = $this->getQueryArray($params);
    		$query_results = new \WP_Query($query_array);
    		
    		
    	    $additional_params['query_results'] = $query_results;
    	    $additional_params['holder_data']          = musea_elated_get_holder_data_for_cpt( $params, $additional_params );
    
    	    $additional_params['holder_classes'] = $this->getHolderClasses($params, $args);
    	    $additional_params['inner_classes']  = $this->getInnerClasses($params);
    	    $additional_params['data_attrs']     = $this->getDataAttribute($params);
    	
    	    $params['this_object'] = $this;
    	    
    	    $html = musea_shows_get_cpt_shortcode_module_template_part('shows', 'show-list', 'show-holder', $params['type'], $params, $additional_params);
    	    
            return $html;
    	}
    
    	/**
        * Generates show list query attribute array
        *
        * @param $params
        *
        * @return array
        */
    	public function getQueryArray($params){
    		$query_array = array(
    			'post_status'    => 'publish',
    			'post_type'      => 'show-item',
    			'posts_per_page' => $params['number_of_items'],
    			'orderby'        => $params['orderby'],
    			'order'          => $params['order']
    		);
    		
    		$field = get_field('date_de_debut');
    		if (!empty ($field)) {
    			$query_array['meta_key'] = 'date_de_debut';
    			$query_array['orderby'] = 'meta_value';
    		}
    
    		if(!empty($params['category'])){
    			$query_array['show-category'] = $params['category'];
    		}
    
    		$show_ids = null;
    		if (!empty($params['selected_shows'])) {
                $show_ids = explode(',', $params['selected_shows']);
    			$query_array['post__in'] = $show_ids;
    		}
    		
    		if ( ! empty( $params['next_page'] ) ) {
    			$query_array['paged'] = $params['next_page'];
    		} else {
    			$query_array['paged'] = 1;
    		}
    		
    		return $query_array;
    	}
    	
    	public function getLoadMoreStyles( $params ) {
    		$styles = array();
    		
    		if ( ! empty( $params['load_more_top_margin'] ) ) {
    			$margin = $params['load_more_top_margin'];
    			
    			if ( musea_elated_string_ends_with( $margin, '%' ) || musea_elated_string_ends_with( $margin, 'px' ) ) {
    				$styles[] = 'margin-top: ' . $margin;
    			} else {
    				$styles[] = 'margin-top: ' . musea_elated_filter_px( $margin ) . 'px';
    			}
    		}
    		
    		return implode( ';', $styles );
    	}