Please, help me with the matter discussed below:
I have registered this shortcode:
[category_post title="world news" category="world news" link="#"]
to call different categories. But the problem is when I post and select a single category, the post is shown in all category. But, I don’t want this. I want the post to show only in that category that has been mentioned in the short-code. Can anyone help me to solve this problem?
Please, have a look at the picture and also I have given u the function here:
/* Register shortcode for querying custom category post *********/
function category_post_shortcode($atts){
extract( shortcode_atts( array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post' ) );
$q = new WP_Query(
array( 'category' => $category, 'posts_per_page' => '4', 'post_type' => 'post')
);
$list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();
$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
$list .= '
<div class="single_cate_post floatleft">
<a href="'.get_permalink().'">'.$post_thumbnail.'</a>
<a href="'.get_permalink().'"><h3>'.get_the_title().'</h3></a>
<p>'.$post_excerpt.'</p>
<a href="'.get_permalink().'" class="readmore">বিসà§à¦¤à¦¾à¦°à¦¿à¦¤</a>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode')
The
category
parameter forWP_Query
expects the category ID – to query by name, usecategory_name
:http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters