0

I have created a custom post type called "whiz_qt_quote". I have created a shortcode for display all the post . This is working fine. but I would like to display the post for specific category. I need a code which would be something like [quote category="motivation"] and it would only display the posts from the "motivation" category.

I am using the following code for the shortcode at the moment. I just need to add the category attribute somehow:

if (!defined('ABSPATH')) exit;

function whiz_qt_feed_shortcode( $atts ) {
    extract( shortcode_atts( array( 'limit' => 3, 'type' => 'whiz_qt_quote','category' => ''), $atts ) );
    global $paged;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;  

        $args = query_posts(  array ( 
        'posts_per_page' => $limit, 
        'post_type' => $type, 
        'order' => 'ASC', 
        // 'orderby' =>'menu_order', 
        'paged' => $paged ,
        'category_name' => $category) );
        if ( ! empty( $category ) ) {
        $args['category_name'] = $category;
    }
$list = ' ';   
while ( have_posts() ) { the_post();

    $list .= '<article class="listing-view clearfix">' 
    . '<div class="listing-content">' 
    . '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>' 
    .'<p>' . get_the_excerpt() . '</p>'
    . '</div>'
    . '</article>';
}

return 
'<div class="listings clearfix">' 
. $list 
. '<div class="nav-previous">' . get_next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts' ) ) . '</div>'
. '<div class="nav-next">' . get_previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>' ) ) . '</div>'
. '</div>' .
wp_reset_query();

}
add_shortcode( 'quote', 'whiz_qt_feed_shortcode' );
?>`
3
  • Please clean up your code and explain what your issue issue is. This is justt a dump of code which means nothing. Thank you :-) Jul 8, 2015 at 10:40
  • I have cleaned up your code. But please reread my previous comment: ...explain what your issue ... is. In other words, file an edit and tell us where are you stuck implementing the category Jul 8, 2015 at 11:16
  • first of all thanks for your feedback. i need a shortcode that display the post according to catagory. it should be dynamically. please check my code then tell me i am doing wrong. Jul 8, 2015 at 11:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.