Remove duplicated posts from Widget
-
Hello,
My WP theme includes 2 top sections that each one shows the latest 2 posts. Below these 2 sections there are sections of categories I choose. Each category section is basically a widget (theme-built-in widget) contains the last posts from each category.
:
In order to remove duplicate posts from the 2 top categories I got the following code:if ( $newscard_settings['newscard_banner_featured_posts_1_hide'] === 0 ) { $featured_post_1_ids = wp_list_pluck( $newscard_get_featured_post_1->posts, 'ID' ); $post_type_fp_2['post__not_in'] = array_unique( array_merge( $post_type_fp_2['post__not_in'], $featured_post_1_ids ) ); }What is the code that will make sure the categories section doesn’t contain posts that are in the 2 top sections?
The widget code attached in the first comment-
This topic was modified 5 years, 8 months ago by
Jan Dembowski. Reason: Formatting
-
This topic was modified 5 years, 8 months ago by
Viewing 2 replies - 1 through 2 (of 2 total)
-
Widget code:
function newscard_widgets_init() { // Registering Front Page Template Content Section register_sidebar(array( 'name' => __('Front Page Content Section', 'newscard') , 'id' => 'newscard_front_page_content_section', 'description' => __('Shows widgets on Front Page Template Content Section. Suitable widget: TH: Horizontal/Vertical Posts, TH: Card/Block Posts and TH: Recent Posts', 'newscard'), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', )); . . . register_widget("newscard_horizontal_vertical_posts"); register_widget("newscard_card_block_posts"); register_widget("newscard_recent_posts"); } add_action('widgets_init', 'newscard_widgets_init'); /****************************************************************************************/ /** * Widget for Front Page Template. * Construct the widget. * i.e. Posts. */ class newscard_horizontal_vertical_posts extends WP_Widget { function __construct() { $widget_ops = array( 'classname' => 'newscard-widget-horizontal-vertical-posts', 'description' => __('Display Horizontal/Vertical Posts', 'newscard') ); parent::__construct(false, $name = __('TH: Horizontal/Vertical Posts', 'newscard') , $widget_ops); }-
This reply was modified 5 years, 8 months ago by
Jan Dembowski. Reason: Formatting
Moved to Fixing WordPress, this is not an Developing with WordPress topic.
My WP theme
That’s theme specific. Which theme?
-
This reply was modified 5 years, 8 months ago by
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Remove duplicated posts from Widget’ is closed to new replies.