php - Get Posts Based on Category Wordpress -
i have 2 categories in wordpress. 1 events , 1 news. have fetch posts in 2 categories in same page. there 4 posts in news category. , events can add user. have display first 8 events based on date of post. writing both categories using 2 queries , moving array.
i've coded given below:
$event_title = array(); $event_author = array(); $event_content = array(); $event_thumbnail = array(); $event_counter = 0 ; $arg = array( 'numberposts' => 8, 'offset' => 0, 'category' => 17, 'orderby' => 'post_date', 'order' => 'asc', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true ); $events = new wp_query( $arg ); if ($events->have_posts()) : while ($events->have_posts()) : $events->the_post(); $event_title[$event_counter] = get_the_title(); $event_author[$event_counter] = get_the_author(); $event_content[$event_counter] = get_the_content(); $event_thumbnail[$event_counter] = get_the_post_thumbnail(); $event_counter++; endwhile; endif;
the category id events 17, i've find id using method echo get_cat_id( "events" );
the problem here posts not fetched on basis of category. takes first 8 posts withou considering category. how can solve issue.
in code use $arg, 'category' => 17, in codex written:
cat (int) - use category id. category_name (string) - use category slug (not name). category__and (array) - use category id. category__in (array) - use category id. category__not_in (array) - use category id.
so need use cat number of category or use array category__in
Comments
Post a Comment