Example #1
0
function listdocs_func($atts)
{
    extract(shortcode_atts(array('type' => 'any', 'cat' => 'any', 'desc' => false), $atts));
    $cat_id = $cat;
    $doctyp = $type;
    $taxonomies[] = 'category';
    $post_type[] = 'attachment';
    $post_cat = get_terms_by_media_type($taxonomies, $post_type);
    if ($cat_id != "any") {
        $catterm = get_category_by_slug($cat_id);
        $catname = $catterm->name;
        $catid = $catterm->term_id;
    } else {
        $catname = __('All categories', 'govintranet');
    }
    if ($doctyp != "any") {
        $dtterm = get_term_by('slug', $doctyp, 'document-type');
        $dtname = $dtterm->name;
        $dtid = $dtterm->term_id;
    } else {
        $dtname = __('All document types', 'govintranet');
    }
    // get all document types for the left hand menu
    $args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false);
    $subcat = get_terms('document-type', $args);
    $cathead = '';
    if ($cat_id != 'any' && $doctyp != 'any') {
        // cat and doc type
        //tax queries need to be meta queries for document_type
        $docs = get_posts(array('post_type' => 'attachment', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $cat_id)), 'meta_query' => array(array('key' => 'document_type', 'compare' => "LIKE", 'value' => '"' . $dtid . '"'))));
    }
    if ($cat_id == 'any' && $doctyp != 'any') {
        // single doc type
        $docs = get_posts(array('post_type' => 'attachment', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, 'meta_query' => array(array('key' => 'document_type', 'compare' => "LIKE", 'value' => '"' . $dtid . '"'))));
    }
    if ($cat_id == 'any' && $doctyp == 'any') {
        // no filter
        $inlist = array();
        foreach ($subcat as $term) {
            $inlist[] = $term->term_id;
        }
        $docs = get_posts(array('post_type' => 'attachment', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, 'meta_query' => array(array('key' => 'document_type', 'value' => '', 'compare' => '!='))));
    }
    if ($cat_id != 'any' && $doctyp == 'any') {
        // single cat
        $inlist = array();
        foreach ($subcat as $term) {
            $inlist[] = $term->term_id;
        }
        $docs = get_posts(array('post_type' => 'attachment', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $cat_id)), 'meta_query' => array(array('key' => 'document_type', 'value' => '', 'compare' => '!='))));
    }
    $postsarray = array();
    foreach ($docs as $doc) {
        //if ( substr($doc->post_mime_type,0,5) == 'image' ) continue; //filter out images
        $postsarray[] .= $doc->ID . ",";
    }
    if (count($docs) == 0) {
        $postsarray[] = '';
    }
    $counter = 0;
    $docs = new wp_query(array('orderby' => 'title', 'order' => 'ASC', 'post_status' => 'inherit', 'posts_per_page' => -1, 'post_type' => 'attachment', 'post__in' => $postsarray));
    $html = '<ul class="docmenu">';
    global $post;
    if ($docs->have_posts()) {
        while ($docs->have_posts()) {
            $docs->the_post();
            $html .= '<li><a href="' . $post->guid . '">';
            $html .= '' . $post->post_title;
            $html .= '</a>';
            if ($post->post_content && $desc) {
                $html .= '<br>' . $post->post_content . '</li>';
            }
        }
    }
    $html .= '</ul>';
    return $html;
}
Example #2
0
        $cathead = '';
        ?>
</div>

<div class="col-lg-5 col-md-6 col-sm-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-6">
	<div id="document_category_dropdown" class="widget-box">
		<h3 class="widget-title"><?php 
        _e('Category', 'govintranet');
        ?>
</h3>
		<?php 
        $taxonomies[] = 'category';
        $post_type[] = 'attachment';
        $post_cat = get_terms_by_media_type($taxonomies, $post_type);
        if ($post_cat) {
            ?>
			<div class="btn-group">
			<img id="doccatspinner" class="hidden" src="<?php 
            echo get_stylesheet_directory_uri() . '/images/small-squares.gif';
            ?>
" />
			<button id = "doccatbutton" type="button" class="btn btn-primary dropdown-toggle2" data-toggle="dropdown">
			<?php 
            echo $catname;
            ?>
</button>
			<ul class='dropdown-menu docspinner' role="menu">
			<?php 
            if ($doctyp) {