Shortcode defined in: /home/epph681n2v0q/public_html/aavishkaarcapital.in/wp-content/plugins/heateor-portfolio-filter/heateor-portfolio-filter.php
Code content:<?php
/*
Plugin Name: Portfolio Filter
Plugin URI: https://www.heateor.com
Description: Includes a Filter for the portfolio list
Version: 1.0
Author: Team Heateor
Author URI: https://www.heateor.com
License: GPL2+
*/
defined( 'ABSPATH' ) or die( "Cheating........Uh!!" );
define( 'HEATEOR_PF_VERSION', '1.0' );
/**
* Includes a Filter for the portfolio list
*/
function heateor_portfolio_listing($params){
echo '<div class="heateor-portfolio-filter"><select id="dropdown_geography" style="
width: 20%;
margin-right: 10px;
float: left;
"> <option value="">Filter by Geography</option><option value="India">India</option><option value="Emerging Asia">Emerging Asia</option><option value="Sub-Saharan Africa">Sub-Saharan Africa</option></select>
<select id="dropdown_sector" style="
width: 20%;
margin-right: 10px;
float: left;
"> <option value="">Filter by Sector</option><option value="Food and Agriculture">Food and Agriculture</option><option value="Financial Inclusion">Financial Inclusion</option><option value="Essential Services">Essential Services</option></select>
<select id="dropdown_type" style="
width: 20%;
margin-right: 10px;
float: left;
"><option value="">Filter by Type</option><option value="Equity">Equity</option> <option value="Credit">Credit</option></select></div>
<div class="responsiveclearboth"></div>
<a href="https://aavishkaarcapital.in/portfolios/"><button class="filtermainbtnmbl">Clear</button></a>
<script>
var heateoSortQruerystring = {};
jQuery( "#dropdown_geography" ).on( "change", function( e ){
heateoSortQruerystring.geography = jQuery( this ).val();
heateorFilterPortfolio();
});
jQuery( "#dropdown_sector" ).on( "change", function( e ){
heateoSortQruerystring.Sectors = jQuery( this ).val();
heateorFilterPortfolio();
});
jQuery( "#dropdown_type" ).on( "change", function( e ){
heateoSortQruerystring.Type = jQuery( this ).val();
heateorFilterPortfolio();
});
function heateorFilterPortfolio() {
console.log(heateoSortQruerystring);
jQuery.ajax({
type: "GET",
dataType: "json",
url: "' . get_admin_url() . 'admin-ajax.php",
data: {
action: "heateor_portfolio_filter",
qs: heateoSortQruerystring,
},
success: function(data, textStatus, XMLHttpRequest){
console.log(data);
if(data.status == 1 && data.result.length !== undefined && data.result.length > 0){
jQuery("div.elementor-shortcode").find("div.tgr-item-title h3").each(function(){
if ( heateorInArray(jQuery(this).text(),data.result)) {jQuery(this).closest("div.tgr-grid-item").css("display","flex");}else{jQuery(this).closest("div.tgr-grid-item").css("display","none");}
});
} else if (data.result.length == 0) {
jQuery("div.elementor-shortcode").find("div.tgr-item-title h3").each(function(){
jQuery(this).closest("div.tgr-grid-item").css("display","none");
});
}
},
error: function(a, b, c){
console.log( JSON.stringify(a) + " " + JSON.stringify(b) + " " + c );
}
});
}
function heateorInArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
</script>';
}
add_shortcode('Heateor-Portfolio', 'heateor_portfolio_listing');
function heateor_portfolio_filter_results() {
$querystring = '';
if ( isset( $_GET['qs'] ) && $_GET['qs'] ) {
$querystring = $_GET['qs'];
$sectorsArray = array();
$geoArray = array();
$typeArray = array();
if(isset( $querystring['geography'] ) && $querystring['geography']){
$geoArray = array(
'key' => 'geography',
'value' => trim($querystring['geography']),
'compare' => '=',
);
}
if(isset( $querystring['Sectors'] ) && $querystring['Sectors']){
$sectorsArray = array(
'key' => 'Sectors',
'value' => trim($querystring['Sectors']),
'compare' => '=',
);
}
if(isset( $querystring['Type'] ) && $querystring['Type']){
$typeArray = array(
'key' => 'Type',
'value' => trim($querystring['Type']),
'compare' => '=',
);
}
if(count($geoArray) == 0 && count($sectorsArray) == 0 && count($typeArray) == 0){
$the_query = new WP_Query(
array(
'cat' => 36,
'nopaging' => true
)
);
} else {
$the_query = new WP_Query(
array(
'cat' => 36,
'nopaging' => true,
'meta_query' => array(
'relation' => 'AND',
$geoArray,
$sectorsArray,
$typeArray
)
)
);
}
} else {
$the_query = new WP_Query(
array(
'cat' => 36,
'nopaging' => true
)
);
}
$html = '';
$post_names = array();
if ( isset( $the_query->posts ) && is_array( $the_query->posts ) && count( $the_query->posts ) > 0 ) {
foreach ( $the_query->posts as $filter_post ) {
$post_names[] = $filter_post->post_title;
}
} else {
$html .= 'Sorry, no posts matched your criteria.';
}
wp_reset_postdata();
exit( json_encode( array( 'status' => 1, 'result' => $post_names ) ) );
}
add_action( 'wp_ajax_heateor_portfolio_filter', 'heateor_portfolio_filter_results' );
add_action( 'wp_ajax_nopriv_heateor_portfolio_filter', 'heateor_portfolio_filter_results' );