Seach

short code plugin in WordPress

<?php
/*
Plugin Name: shortcode
Plugin URI: https://hhiitthhiinn.blogspot.in
Version: 1.0
Author: Hithin
Author URI: https://hhiitthhiinn.blogspot.in
*/
function code($atts) {

$default = array
(
'type' => 'post',
'count' => -1,
'categoryid' => '',
'order' => 'ASC',
'taxonomy' => ''
);
    $attr = shortcode_atts($default,$atts);
$type = $attr['type'];
$count = $attr['count'];
$categoryid =$attr['categoryid'];
$taxonomy = $attr['taxonomy'];
$args = array(
'posts_per_page'   => $count,
'offset'           => 0,
'orderby'          => 'date',
'order'            => 'DESC',
'include'          => '',
'exclude'          => '',
'meta_key'         => '',
'meta_value'       => '',
'post_type'        => $type,
'post_mime_type'   => '',
'post_parent'      => '',
'author'    => '',
'author_name'    => '',
'post_status'      => 'publish',
'suppress_filters' => true,
'tax_query' => array(
        'taxonomy' => $taxonomy,
'field' => 'term_id',
        'terms' =>$categoryid
    )
);
$posts = get_posts( $args );
foreach($posts as $key=>$item)
{
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $item->ID ), 'thumbnail' );
$image = $image[0];
?>
<style>
.item {
    float: left;
    border: 1px double #ccc;
    margin: 5px !important;
}

</style>
<div  class="slick-slide item slick-cloned" data-slick-index="-3" aria-hidden="true" tabindex="-1" >
<figure class="slick-slide-inner">
<a target="_blank" href="<?php echo get_post_permalink($item->ID); ?>"><img class="slick-slide-image" src="<?php echo $image; ?>" alt="poster_5_up"></a>
</figure>

</div>
<?php
}
?>
<?php
}
add_shortcode('code', 'code');
?>
[code  parmeters (categoryid,taxonamy,count,order) ]