Skip to content

Instantly share code, notes, and snippets.

@niamrox
Last active July 14, 2017 14:24
Show Gist options
  • Save niamrox/226779cd8e12f7df9c215b4977640e42 to your computer and use it in GitHub Desktop.
Save niamrox/226779cd8e12f7df9c215b4977640e42 to your computer and use it in GitHub Desktop.
Multiple Select Form Based on Dynamic Taxonomy Query
<?php
/*
Element Description: VC Info Box
*/
// Element Class
class ClientInfoBoxLoop extends WPBakeryShortCode
{
// Element Init
function __construct()
{
add_action('init', array($this, 'client_info_box_loop_mapping'));
add_shortcode('client_info_box_loop', array($this, 'client_info_box_loop_html'));
}
// Element Mapping
public function client_info_box_loop_mapping()
{
$clients_taxonomy = array();
$clients_taxonomy = explode(',', get_option('pxlr-link-taxonomy'));
$clients_taxonomy[] .= 'client_category';
foreach ($clients_taxonomy as $key => $value) {
$taxonomy_term_list=array();
$taxonomy_term_list[$value] = get_terms(array(
'taxonomy' => $value,
'hide_empty' => true,
) );
$taxonomy_term_group_single=$taxonomy_term_list[$value];
$client_taxonomy_list=array();
foreach ( $taxonomy_term_group_single as $term ) :
$client_taxonomy_list[$value][ $term->name ] = $term->term_id;
endforeach;
//print_r($client_taxonomy_list);
}
$select_taxonomy='';
wp_reset_postdata();
// Stop all if VC is not enabled
if (!defined('WPB_VC_VERSION')) {
return;
}
// Map the block with vc_map()
vc_map(
array(
'name' => __('Client Info Box Loop', PXLR_PLUGIN_TEXTDOMAIN),
'base' => 'client_info_box_loop',
'description' => __('Client Info Box Loop', PXLR_PLUGIN_TEXTDOMAIN),
'category' => __('Pxlr Clients', 'text-domain'),
'icon' => PXLR_PLUGIN_URI . '/vc_shortcodes/img/vc-icon/client-infobox-loop.png',
'params' => array(
array(
// I want to put loop here based on my condition
"type" => "textfield",
"admin_label" => TRUE,
"heading" => __("Number Of Client To Show", 'text-domain'),
"param_name" => "client_number",
"description" => __("Input number of client you want to show per page", PXLR_PLUGIN_TEXTDOMAIN)
),
),
)
);
}
// Element HTML
public function client_info_box_loop_html($atts)
{
// Params extraction
extract(
shortcode_atts(
array(
'client_id' => '',
),
$atts
)
);
// Fill $html var with data
ob_start(); ?>
<div class="client-infobox-wrap">
<!-- Info box default -->
<div class="client-infobox-default clearfix">
<div class="col-md-6">
<?php
$post = get_post($atts['client_id']); //assuming $id has been initialized
setup_postdata($post); ?>
<div class="client-infobox-company-details text-left">
<div class="client-infobox-image">
<?php
$thumbnail = get_the_post_thumbnail_url($post->ID);
$logo_size = explode(',', $atts['client_logo_size']);
?>
<img src="<?php echo esc_url($thumbnail) ?>" alt="Info Box Image"
height="<?php echo $logo_size[0] ?>" width="<?php echo $logo_size[1] ?>">
</div>
<h2 class="client-infobox-title"><?php echo $post->post_title; ?></h2>
<div class="client-infobox-text">
<p><?php echo get_post_meta($atts['client_id'], 'pxlr-client-overview', TRUE); ?></p>
</div>
<div class="client-infobox-button">
<a href="<?php echo get_permalink($post->ID) ?>" class="btn btn-primary btn-md">Case
Study</a>
</div>
</div>
</div>
<div class="col-md-6">
<div class="client-infobox-testimonials">
<span><?php echo esc_attr(get_post_meta($atts['client_id'], 'pxlr-feed-back-statement', TRUE)) ?></span>
<div class="client-infobox-author-details text-right">
<?php
$contact_person_group = get_post_meta($post->ID, 'pxlr-contact-person-group');
if (!empty($contact_person_group)) {
$single_contactPerson_group = $contact_person_group[0][0]; ?>
<span><?php echo esc_attr($single_contactPerson_group['pxlr-contact-person-name']) ?></span>
<p><?php echo esc_attr($single_contactPerson_group['pxlr-contact-person-department']) ?></p>
<p><?php echo $post->post_title; ?></p>
<?php } ?>
</div>
</div>
<div class="client-infobox-achievement">
<ul class="list-inline text-center">
<li>
<span
class="achievement-count"><?php echo esc_attr(get_post_meta($atts['client_id'], 'pxlr-number-of-employees', TRUE)) ?></span>
<span class="text-uppercase">Employees</span>
</li>
<?php
$custom_field_group = get_post_meta($post->ID, 'pxlr-client-custom-data');
$i = 0;
for ($i = 0; $i <= 3; $i++) {
$custom_field = '';
}
?>
<li>
<span
class="achievement-count"><?php echo $custom_field_group[0][0]['pxlr-custom-field-value'] ?></span>
<span
class="text-uppercase"><?php echo $custom_field_group[0][0]['pxlr-custom-field-title'] ?></span>
</li>
<li>
<span
class="achievement-count"><?php echo $custom_field_group[0][1]['pxlr-custom-field-value'] ?></span>
<span
class="text-uppercase"><?php echo $custom_field_group[0][1]['pxlr-custom-field-title'] ?></span>
</li>
<li>
<span
class="achievement-count"><?php echo $custom_field_group[0][2]['pxlr-custom-field-value'] ?></span>
<span
class="text-uppercase"><?php echo $custom_field_group[0][2]['pxlr-custom-field-title'] ?></span>
</li>
</ul>
</div>
</div>
</div>
<?php wp_reset_postdata(); ?>
</div>
<?php
return ob_get_clean();
}
} // End Element Class
// Element Class Init
new ClientInfoBoxLoop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment