Sidebar Widget – Exclude main post from list
-
I have a custom widget plugin that lists post links in the sidebar. I want it to exclude the post if it is already on that page.
My code is below – I’ve commented out the lines where I have tried to achieve excluding the main post (as they don’t work). Its working fine without these lines.// Front End Display function widget($args, $instance) { echo $args[‘before_widget’]; if ( ! empty( $instance[‘title’] ) ) { echo $args[‘before_title’] . apply_filters( ‘widget_title’, $instance[‘title’] ) . $args[‘after_title’]; } $args = array( // global $post; // $exclude = $GLOBALS[‘current_id’]; //$args = array( ‘post_type’ => ‘events’, //’post__not_in’ => array($exclude), // ); ‘posts_per_page’ => 5, ‘orderby’ => ‘date’, ‘order’ => ‘ASC’, ‘tax_query’ => array( ‘relation’ => ‘AND’, //Term ‘Exhibitions’ array( ‘taxonomy’ => ‘types’, ‘field’ => ‘id’, ‘terms’ => array( 13 ), ‘operator’ => ‘IN’ ), //Not with term ‘Archive’ array( ‘taxonomy’ => ‘status’, ‘field’ => ‘id’, ‘terms’ => array( 7 ), ‘operator’ => ‘NOT IN’ ) ) );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Sidebar Widget – Exclude main post from list’ is closed to new replies.